This study presents an optimization algorithm for Model Predictive Control (MPC) of the HVAC systems in multi-family residential buildings assessing the performance of four objective functions. Implemented in C++, using the free OR-Tools optimization library, the model is formulated a Mixed Integer-Linear Programming (MILP) problem. The study analyses the results of tests conducted on a 20-dwelling block in Switzerland across various weather and occupancy conditions, resulting in a parametric study of 64 cases.The models developed for the MPC are Grey-box type for the interconnected energy systems: the building, thermal storage tanks, a heat pump the ventilation system and PV collectors, highlighting a radiant wall heating system integrated into the building facade. The tanks and the heat pump models were informed with manufacturer data, while for the building a R3C3 thermal-electrical equivalent model was developed, calibrated using TRNSYS simulations with a root mean square error of 1.7%.Findings demonstrate how the algorithm optimizes the operation according to the desired criteria, while ensuring indoor comfort with a 15-minute time resolution. The time execution of the majority of cases is under 3 min in a low-specs computer, affirming its practical viability for real-world implementation.