Besides satisfying the energy demands of buildings, distributed generation can contribute toward environmental conservation. However, determining the best configuration and operational strategy for these systems is a complex task due to the available technology options and the dynamic operating conditions of buildings and their surroundings. This work addressed the synthesis and optimization of an energy system for a commercial building (hotel). Electricity, hot water, and cooling demands were established for a hotel located in Northeast Brazil. The optimization problem was based on mixed-integer linear programming and included conventional equipment, solar energy resource (photovoltaic and thermal technologies), and biomass. The objective function of the optimization was to minimize annual economic costs, which involved considering the capital and operation costs. A reference system was established for comparison purposes, where energy demands were met conventionally (without cogeneration or renewable energy), whose annual cost was BRL 80,799. Although the optimal solution did not rely on cogeneration, it benefited from the high degree of energy integration and had a total annual cost of BRL 24,358 (70% lower). The optimal solution suggested the installation of 70 photovoltaic panels and used biomass (sugarcane bagasse) to operate a hot water boiler. Solar collectors for hot water production were not part of the optimal solution. Sensitivity analyses were also carried out, varying the electricity and natural gas tariffs, and the type of biomass employed, but the configuration of the system did not change compared with the optimal economic solution.