The study addresses the integration of hybrid hydrogen (H2) and battery (BT) energy storage systems into a renewable energy microgrid comprising solar photovoltaic (PV) and wind turbine (WT) systems. The research problem focuses on improving the effectiveness and computational efficiency of energy management systems (EMS) while ensuring high system reliability. Despite the existing optimization methods for hybrid microgrids, challenges remain in optimizing energy storage and capacity planning in grid-connected microgrids. To solve this, we propose the use of the Levy Flight Algorithm (LFA) to optimize the capacities of PV, WT, H2 tanks, electrolyzers (EL), fuel cells (FC), and BT, which presents a complex nonlinear optimization challenge. The novelty of this study lies in integrating the LFA with a rule-based EMS, enhancing system reliability and efficiency. The proposed approach significantly reduces the annualized system cost (ASC) and the levelized cost of energy (LCOE). The result demonstrate that the LFA outperforms methods like the Salp Swarm Algorithm (SSA), Particle Swarm Optimization (PSO), Grey Wolf Optimization (GWO) and Genetic Algorithm (GA), yielding cost savings of $3,309, $5,297, $4,484, and $5,129 respectively. The LFA achieves the lowest LCOE at $0.275/kWh, compared to $0.278/kWh with SSA, $0.289/kWh with GA, $0.280/kWh with PSO and $0.283/kWh with GWO. This research contributes to the broader scientific community by providing a more efficient approach to optimizing renewable energy microgrids with hybrid storage systems, thus promoting eco-friendly and cost-effective energy solutions. The proposed system design offers a pathway to future energy systems with high renewable integration, especially as technology advances and costs continue to decrease.