This research demonstrates the application of novel optimization methods in the realm of renewable energy and contributes to the development of environmentally friendly electricity generation and consumption. In this study, an improved version of the Al-Biruni algorithm has been proposed for Hybrid Renewable Energy Systems (HRES) optimization, which includes fuel cells, photovoltaic cells, and windmills. The algorithm considers supply, demand, and energy storage constraints and seeks the best combination of energy sources to meet load demand while reducing total system cost. Inspired by ancient Iranian philosopher Abu Biruni, the proposed method includes modifications to explore solution space efficiently and improve answer value. The proposed HRES model is applied to a case study from Dunhuang City, China, and its findings are validated by comparing it with other optimization approaches. The Modified Al-Biruni Earth Radius (MBER) algorithm is found to be the most efficient and reliable system, costing 4.23 million units of currency. Compared to other optimization approaches, MBER exhibited a total cost of 4.1 million US dollars, 0.009, 3.7, 3.7, LPSP, and 356 h per year. The overall cost is 5.26 million units of currency with a 0.5% Loss of Power Supply Probability (LPSP), which directly impacts system performance and dependability. The improved Al-Biruni algorithm can efficiently optimize the system, reduce costs, and increase load supply, contributing to the growth of renewable energy sources and the application of advanced meta-heuristic techniques in complex energy systems.