Fast depleting reserves of fossil fuels, increasing the cost of fuel for conventional power generation, the use of renewable sources of power generation has become an inevitable reality. The paper makes a feasibility assessment of standalone hybrid renewable energy system based on (PV/Wind/Battery) as a possible source to electrification for an education institution namely Mohammadia School of Engineers in Rabat, Morocco, (33°59′ 58″ N, 6°51′ 7″ W). The objective of the study is to optimize the size and the cost of the microgrid system at the selected site to meet the electrical demand of a load. The modeling, optimization and analysis of the hybrid system are carried out using MATLAB software. A comparative algorithm study is carried out with Invasive Weed Optimization (IWO) and the hybrid IWO-PSO algorithm. The microgrid system is evaluated on the basis of Net Present Cost (NPC) and Levelised Cost of Energy (LCOE). Simulation results show that the Hybrid IWO-PSO have more promising results than the other algorithm.