Resumen: In the quest for a better use of energy resources, energy integration and cogeneration strategies have been employed in the industrial and commercial sectors with considerable benefits realized. However, the residential sector remains underexplored. An optimization procedure should be carried out whenever there is a need to ensure or verify the economic viability of an energy system. This study uses Mixed Integer Linear Programming to optimize the energy supply to a residential building, with 20 floors and 40 apartments, located in the city of João Pessoa (Northeast Brazil). The equipment available includes gas engines, electric and natural gas boilers, heat exchangers, cooling towers, and absorption and mechanical chillers. The optimization establishes the optimal system configuration and operational strategy (operation throughout the year). Economic, technical, and legal aspects were considered in the minimization of the total annual costs associated with the building's energy supply. The energy demands were calculated on an hourly basis, throughout one year, by the EnergyPlus software and corresponded to hot water (83 MWh/year), electricity (171 MWh/year) and cooling (242 MWh/year) demands. The optimal system was entirely reliant on the electric grid to meet the electricity demand directly and to satisfy heating and cooling demands by means of an electric hot water boiler and a mechanical chiller. The optimal solution is tested by varying, within reasonable limits, selected parameters: natural gas and electricity tariffs, the behavior of residents, amortization factor and relationship between the tariffs of electricity and natural gas. Idioma: Inglés DOI: 10.2298/TSCI200718335M Año: 2021 Publicado en: Thermal Science 25, 5 (2021), 3969-3986 ISSN: 0354-9836 Factor impacto JCR: 1.971 (2021) Categ. JCR: THERMODYNAMICS rank: 44 / 63 = 0.698 (2021) - Q3 - T3 Factor impacto CITESCORE: 2.7 - Energy (Q3)