Decarbonizing the building sector requires integrated approaches capable of capturing interactions between technologies, energy carriers, and spatial heterogeneity. This study develops a multi-period cost-optimization framework to identify the optimal technological mix for space heating, cooling, and domestic hot water under long-term decarbonization pathways. The model combines high-resolution spatial demand assessment with a national-scale optimization implemented in the open-source Oemof framework, explicitly representing retrofit measures, hybrid systems, and renewable-based technologies. The framework is applied to the Italian building sector over 2021–2050 under emission constraints. Results show a progressive phaseout of gas boilers in favor of electric and hybrid heat pumps, district heating, and biomass systems, with strong regional differentiation driven by climatic conditions. Building retrofit plays a central role, enabling around 30% energy savings and facilitating the deployment of low-temperature technologies. The transition entails an additional cumulative system cost of approximately €320 billion (€12100 per household), driven by higher capital investments and partially offset by reduced operating costs. The proposed approach provides a transparent and flexible tool to support the design of cost-effective and spatially tailored decarbonization strategies.