A sustainable geothermal-based system is designed and optimized for the utility services of a smart residential building in a coastal city of Iran. In particular, humidification-dehumidification (HDH) desalination system is integrated with a heat pump (HP) system to meet the heating load, cooling load, and freshwater required by a five-story smart residential building. The electricity required by the humidification-dehumidification integrated with heat pump and the residential building is also provided by an organic Rankine cycle (ORC), which extracts the required heat from the geothermal sources. To obtain the amount of electrical energy consumption and required amount of air for ventilation of the building, EnergyPlus software has been utilized. The designed multi-generation system has been analyzed from thermodynamic, exergy and exergo-economic aspects. Also, by analyzing the sensitivity of the system to input parameters, the most influential parameters on the first-law efficiency and the unit cost of purified water (UCPW) were identified. An artificial intelligence technique has been used to predict the building's demands. Subsequently, multi-objective optimization of the system was done using the genetic algorithm to identify the optimal performance point. The obtained results demonstrate that optimal values of the first-law efficiency of the system and UCPW are 46.66 % and 4.49 US$/m3, respectively.