Rising energy costs, climate change impacts, and transmission losses have increased demand for renewable energy sources and decentralized solutions. As more people seek smart living and working environments, integrated smart microgrids powered by hybrid renewable systems have become attractive solutions for off-grid and on-grid communities. This study proposes designing a solar-wind-battery hybrid microgrid supplying a medical load et al.-Ain Al-Sokhna, Egypt. The optimization objectives aim to minimize the loss of power supply probability (LPSP %) and the levelized cost of energy (LCOE, $/kWh). A key consideration when designing and optimizing hybrid microgrids is the energy management strategy, which coordinates different generation sources and fluctuating load demand. Therefore, optimization algorithms were applied to balance energy flows while meeting loads, mitigating weather impacts, and preventing overcharging/deep discharge of battery storage. Models of wind turbines, photovoltaic panels, and battery storage were developed to simulate and analyze proposed microgrid operations. A multi-objective optimization approach evaluated LPSP and LCOE metrics using transit search, grey wolf, and particle swarm algorithms to find optimal system configurations. The optimization algorithms demonstrated varying performances in minimizing the multi-objective functions for the on-grid and off-grid microgrids. The particle-swarm optimization technique is the best solution for the off-grid system, which contains PV, wind, and battery storage, with a minimum LCOE of 0.3435 $/kWh and an LPSP of 4.5334%. Meanwhile, the transit-search optimization algorithm found the optimal solution for the on-grid configuration according to the objective function, yielding an LCOE of 0.116 $/kWh and an LPSP value of 3.0639 × 10−16. Statistical analysis confirmed that the algorithms generally exhibited stable and robust optimization capabilities. Of the methods, transit search was the most effective overall optimization approach.