An appropriate energy solution for buildings depends on the scale of demand and the availability of the surrounding technical infrastructure. Building energy demand can be altered by the application of various energy efficiency measures whereas the performance of the energy supply system can be changed by the involvement of various technologies. As a result, optimal energy supply options could depend on various parameters that depend on specific contexts. In this study, different options to supply energy to apartment buildings of different energy efficiency levels in Sweden are investigated. Different renewable-based alternatives to produce heat and electricity based on various state-of-the-art technologies are considered. The optimizations are based on the hourly variation throughout the year of energy demand and of different energy supply systems that change with the ambient conditions such as temperature and solar radiation. The results prove that optimal options for a building depend on its scale of energy demand and on the availability of technologies in the market. Also, there is a tradeoff between monetary costs and primary energy use in supplying energy to apartment buildings. This study shows that it is essential to consider the interaction between energy demand and supply to estimate the costs and primary energy use for energy supply alternatives. A heating system with an electric heat pump shows to be primary energy efficient option whereas that with a wood pellet boiler is a more cost efficient once. However, an energy supply option based on a combined heat and power unit using fuel cell technology could potentially be the most cost- and primary energy efficient option for buildings with low energy demand.