Growing renewable energy integration leads to significant fluctuations in electricity generation. To address this challenge, market-based mechanisms for dynamic carbon emission factors and electricity prices are emerging, particularly in regions like China pursuing carbon neutrality. Buildings, with HVAC systems as the largest consumers, require flexible Demand Response (DR) strategies to balance these fluctuations while maintaining occupant comfort. This paper proposes a hierarchical control framework for building HVAC systems. It optimizes operation for various objectives (minimizing energy consumption, reducing electricity costs, and lowering carbon emissions), while ensuring thermal comfort. The framework involves three modules. First is the time-based demand allocation, which uses genetic algorithms to optimize energy use based on future cooling demands, indoor temperature, and fluctuating electricity and carbon prices. It provides building-level temperature setpoints and electricity consumption plans. Second is the spatial indoor demand adjustment, which balances overall cooling load and temperature satisfaction across individual spaces, taking into account room-specific costs and difficulty confidents for temperature adjustments. This module assigns future temperature setpoints to each space. Third is HVAC system follow-up control, which Implements the optimized setpoints for real-time control of the HVAC system. The framework’s effectiveness is verified through application to a real commercial building project. Compared to a baseline scenario, the optimal electricity cost strategy achieved a 6.5% cost reduction, and the optimal carbon emission reduction strategy achieved an 8.2% reduction. Real-world control based on carbon emission optimization resulted in an actual year-on-year carbon emission reduction of 8.7%.