This paper presents a dual-layer approach for managing and controlling an AC Microgrid (MG). The MG integrates a Photovoltaic System (PVS), Wind Turbine System (WTS), a Battery Storage System (BSS), all interconnected with the utility grid. The dual-layer is structured into a Control Layer (CL) and an Energy Management System Layer (EMS-L). The CL proposes an efficient model coupled with a system control, ensuring high power quality for the AC microgrid. This system employs a Particle Swarm Optimization (PSO) algorithm to optimize the set point tracking performance. Simultaneously, the EMS-L utilizes a Sparrow Search Algorithm (SSA) with the objective of minimizing the total operating costs of the AC microgrid. This is achieved by employing a 15-minutes step time over a 24-hours period, enhancing both precision and rapidity of the system's operation. This enhanced temporal resolution effectively models and responds to fluctuations in energy demand, supply variability and environmental factors. This synergistic integration allows for nuanced and efficient energy flow management in order to optimise the MG performance. A significant aspect of the research is the comparative analysis of the proposed SSA-EMS with PSO and Genetic Algorithm (GA), alongside an unoptimized system. This analysis highlights the hybrid methodology's superior efficiency and effectiveness. The robust framework, combining SSA at the EMS layer with PSO at the control layer, has been empirically tested using a real world data to confirm its effectiveness and resilience in practical scenarios. These tests provide solid evidence of the methodology's potential in boosting the sustainable and reliable operation of microgrids. Significantly, the SSA-EMS showcases notable cost efficiency, achieving reductions of 33.34% and 41.18% compared to PSO and GA . Impressively, compared to an unoptimized system, the SSA-EMS demonstrates an even more remarkable cost reduction of 49.43% and 59.10% while considering the impact on battery health constraints.INDEX TERMS Microgrid, energy management system, wind turbine system, photovoltaic system, energy storage system, control systems, sparrow search algorithm.