Optimizing digital twins in the Industrial Internet of Things (IIoT) requires secure and adaptable AI models. The IIoT enables digital twins, virtual replicas of physical assets, to improve real-time decision-making, but challenges remain in trust, data security, and model accuracy. This paper presents a novel framework combining blockchain technology and federated learning (FL) to address these issues. By deploying AI models on edge devices and using FL, data privacy is maintained while enabling collaboration across industrial assets. Blockchain ensures secure data management and transparency, while explainable AI (XAI) enhances interpretability. The framework improves transparency, control, security, privacy, and scalability for self-optimizing digital twins in IIoT. A real-world evaluation demonstrates the framework’s effectiveness in enhancing security, explainability, and optimization, offering improved efficiency and reliability for industrial operations.