This paper introduces an innovative integrated policy secure framework employing blockchain technology to effectively handle optimal structure switching within microgrids. The primary objectives are to enhance electric work for cost reduction and power quality enhancement. The structure utilizes remote switches to adjust the microgrid ' s power supply route to consumers, minimizing resistive power losses. Additionally, it integrates the mobile storage capabilities of electric vehicles (EVs) to enhance microgrid operations. The aging costs of battery for EVs are modeled using Wo <spacing diaeresis>hler curve. An effective modification technique using Dolphin Echolocation is established to enhance algorithm assortment and prevent premature convergence. The study employs a standard test system to evaluate the performance of the proposed model. Simulation results demonstrate that the secure architecture facilitates improved microgrid scheduling through encrypted data packets, optimizing EV charge and discharge. The Energy System Digital Twin (ESDT) plays a crucial role in investigating this stochastic secure energy management architecture for microgrids, incorporating EVs and blockchain. The ESDT dynamically replicates microgrid complexities, integrating stochastic models for renewable energy, EV charging behaviors, and blockchain transactions. This digital twin enables simulations for optimizing EV integration, evaluating blockchain resilience, and strengthening cybersecurity measures. This comprehensive approach within the digital twin framework provides a platform for refinement and innovation, ensuring the development of sustainable, efficient, and secure microgrid ecosystems adaptable to the evolving landscape of renewable energy, EV adoption, and blockchain technology, as well as considering policy in decision making.