In this study, a cogeneration system of heating, cooling and power used with the solar flat plate collectors (FPCs) and photovoltaic panels (PVs) integrates with a multi‐effect distillation through thermal vapor compression (MEE‐TVC), investigated as the first system to meet the loads of heating, cooling, electricity and fresh water. As an innovation, the combination of the first system with cooling and thermal storage tanks have been investigated. The systems are optimized with MATLAB and single‐objective genetic algorithm. The total annual cost considered as the objective function to compare the two systems and 36 and 61 design variables are obtained for the first and second systems, respectively. The design parameters considered for optimization included the capacity of the diesel engine as the prime mover, electrical chiller capacity, absorption chiller capacity, size of the boiler, partial loads of the diesel engine for each hour of the 2 days (1 day for hot months and 1 day for cold months), partial loads of the chillers for each hour of the first days (second day has no cooling load), number of FPCs and PVs, number of effects in the desalination unit, driving steam pressure, feed water flow rate, driving steam flow rate, and electric cooling ratio. The optimization aimed to fulfill the heating, cooling, electricity, and fresh water requirements of a residential town situated in Bandar Abbas, Hormozgan province, Iran. The second system's optimization results were compared with first system. The results have shown that the objective function for the first system was and the initial investment cost was , and for the second system the objective function was and the initial investment cost was . Therefore, by using energy storage, the objective function was reduced by 11.30%.