In this article, the optimal design of a novel multi-generation system for the production of electricity, cooling, heat and freshwater is discussed. In this system, a Proton exchange membrane fuel cell (PEM FC) is used to generate electricity, and the heat produced by it is absorbed by the Ejector Refrigeration Cycle (ERC) and used to provide cooling and heating capacity. A reverse osmosis (RO) desalination system is also used to supply freshwater. The esign variables in this research are operating temperature and pressure and current density of FC, as well as the operating pressure of the HRVG, evaporator, and condenser of the ERC system. In order to optimize the considered system, the exergy efficiency and total cost rate (TCR) of the system are considered as optimization objective functions. To this end, the genetic algorithm (GA) is used and the Pareto front is extracted. Also, three refrigerants R134a, R600 and R123 areused as ERC system refrigerant and their performance are evaluated. Finally, the optimal design point is selected. At the mentioned point, the exergy efficiency is 70.2% and the TCR of the system is 1.78 S/h.