Energy efficiency and renewable energy solutions in buildings is an important and actual research topic. Operating and fixed costs of sustainable energy solutions can be reduced by using optimization models. We developed a novel optimization model and applied it for a mixed-type building with commercial, office, and residential parts in Finland. The model determines the optimal configuration, dimensioning, and operation of different local energy production and storage technologies for power, heat, and cooling. The model is formulated as a large dynamic linear or mixed-integer linear programming model (LP/MILP) for a full year. The result shows that district heating, district cooling, energy storage, heat pumps, and photovoltaics as a hybrid solution for a building can both reduce the combined operating and fixed costs annually by 27100€, and support meeting the nearly Zero Energy Building requirements with E-value limit of 107 kWh/m2/a. Photovoltaics can be profitable when consumed maximally at the building. While heat and cooling storages are cost-efficient for balancing demand and supply, power storages are still too expensive. District heating and heat pump heating worked synergetically together, but district cooling and heat pump cooling were mutually exclusive choices at nearly equal cost.