The optimization of heat and power systems operation is a complex task that involves continuous and discrete variables, operating and environmental constraints, uncertain prices and demands and transition constraints for startups or shutdowns. This work proposes a novel methodology for integrating scheduling optimization and real-time optimization (RTO) in order to face and solve such optimization problem. In a first stage, an offline optimization finds a scheduling for the whole horizon under study, which sets the startups and shutdowns of pieces of equipment with long transition times. A second stage solves a multiperiod RTO, which corrects the forecasts and adapts the model before optimiz-ing the process. Although the proposed methodology is illustrated through a case study consisting in a heat and power system, it can be generalized to other systems and processes. The obtained results show significant improvements in comparison with applying the results of a single offline scheduling optimization.