With the increasing rate of population in big cities around the world, the tendency to build new buildings in the suburb of main cities or to build large apartments in the main cities has been highlighted. In this regard, building residential complexes has seen a dramatic increase in these areas as it makes it possible to build a large number of residential units within a reasonable space. Although these complexes have brought numerous benefits, they are some challenges regarding their construction processes. One main concern associated with these complexes is how to optimally install energy components such as transformers, combined heat and power (CHP) units, boilers etc., in the shared area of apartments in the residential complex. To address this issue, this paper models the energy system of a residential complex as an energy hub and proposes a novel framework to obtain the optimal planning of such an energy hub. In order to address the conflicting desires of the residential complex's builders and the future residents of the residential units, a multiobjective (MO) optimization problem has been considered in the proposed method that simultaneously optimizes the investment costs, operation costs, and the reliability of energy supply. In this regard, a Multi-objective Particle Swarm Optimization (MOPSO) algorithm combined with classical linear programming (LP) optimization method has been proposed to solve the MO optimization problem. In order to demonstrate the effectiveness of the proposed method, a case study including a residential complex with 300 residential units is considered, and the proposed method is implemented in this case study. The numerical results show that the proposed framework can appropriately optimize investment costs, operation costs, and the reliability index simultaneously, and the obtained Pareto frontier gives the investors the freedom to opt for any point from this surface.