Proposing a practical multi-generational system for different climates can be the key for setting up renewablebased systems as an alternative to fossil fuels in different countries. This paper introduced a flexible renewable energy system that is capable of generating multiple forms of energy using solar energy and hydrogen storage, and can operate under diverse weather conditions across four cities in Iran. The system was equipped with a solar unit, photovoltaic panels (PV), heating and cooling units, a desalination technology, a hydrogen production unit, and a fuel cell to supply heating, cooling, electricity and freshwater loads for a residential building. Mashhad (normal), Tabriz (cold), Bandar Abbas (humid), and Yazd (hot and dry) cities were considered as different climates in Iran to suggest the best city based on the present system. Analysis and simulation were conducted, taking into account five perspectives, namely energy, exergy, exergoeconomic, economic, and environmental (5E). This was done utilizing the TRNSYS and Engineering Equation Solver (EES) packages. Multiobjective optimization was carried out to achieve the best performance using the TOPSIS method for the four cities mentioned. The system was grid-connected to sell excess power when there is no need for electricity and receive power when it is needed. Optimization showed that Bandar Abbas has the highest exergy efficiency of the system by 26.3 % and the lowest total cost rate of the whole components by 6.08 $/h. Moreover, the maximum net output power of 28.72 kW was reported in Tabriz. Environmental analysis revealed that the system had the ability to lower CO2 emissions through the generation of clean electricity and avoiding the use of natural gas. This was particularly significant in Bandar Abbas and Yazd, where the maximum reductions in CO2 emissions were obtained at 23.3 tons and 4.4 tons, respectively. In conclusion, the payback period for Mashhad, Tabriz, Bandar Abbas, and Yazd cities was obtained at 6.5 years, 5.8 years, 5.5 years, and 5 years, respectively.