This study investigates the optimization of the size of a solar-wind hybrid microgrid using Particle Swarm Optimization (PSO) to improve energy production efficiency, economic feasibility, and overall sustainability. By using past solar and wind resource data, load demand profiles, and system component specifications, the PSO algorithm effectively maximized the capabilities of solar panels and wind turbines. The findings indicate a significant rise in daily energy production, with a 15% enhancement in solar panel capability and a 12% boost in wind turbine capability. The increased energy production plays a crucial role in dealing with the natural irregularity of renewable resources, hence enhancing the resilience and self-reliance of the microgrid. The economic calculations demonstrate significant improvements in the economic feasibility of the microgrid designs. The Levelized Cost of Energy (LCOE) undergoes a significant 10% decrease, suggesting a more economically efficient energy generation. Moreover, the payback time for the original expenditure is reduced by 15%, indicating faster returns on investment. The economic improvements highlight the practical advantages of using PSO for microgrid size, in line with the goal of creating sustainable energy solutions while minimizing economic costs. The improved performance of Particle Swarm Optimization (PSO) is shown by a thorough comparison study with other optimization approaches, such as Genetic Algorithms (GA) and Simulated Annealing (SA). The superior convergence rate of PSO, together with a 15% enhancement in solution quality relative to GA and SA, underscores the efficiency and efficacy of PSO in traversing the complex solution space associated with microgrid size. PSO’s comparative advantage makes it an effective tool for tackling the intricacies of integrating renewable energy, highlighting its potential for extensive use in microgrid design and optimization. The sensitivity evaluations demonstrate that the solutions optimized by the PSO are resilient even when important parameters vary, thereby highlighting the stability and dependability of the approach. In addition to technical and economic factors, the study evaluates the environmental consequences and social aspects of the optimum microgrid designs. The land use efficiency has seen a 10% enhancement, demonstrating the optimum application of area for renewable energy infrastructure. In addition, there is a 7% improvement in community approval, which demonstrates the algorithm’s ability to effectively handle social aspects and promote a comprehensive and socially acceptable approach to renewable energy projects.