In this paper, we address the problem of the efficient and sustainable operation of data centers (DCs) from the perspective of their optimal integration with the local energy grid through active participation in demand response (DR) programs. For DCs’ successful participation in such programs and for minimizing the risks for their core business processes, their energy demand and potential flexibility must be accurately forecasted in advance. Therefore, in this paper, we propose an energy prediction model that uses a genetic heuristic to determine the optimal ensemble of a set of neural network prediction models to minimize the prediction error and the uncertainty concerning DR participation. The model considers short term time horizons (i.e., day-ahead and 4-h-ahead refinements) and different aspects such as the energy demand and potential energy flexibility (the latter being defined in relation with the baseline energy consumption). The obtained results, considering the hardware characteristics as well as the historical energy consumption data of a medium scale DC, show that the genetic-based heuristic improves the energy demand prediction accuracy while the intra-day prediction refinements further reduce the day-ahead prediction error. In relation to flexibility, the prediction of both above and below baseline energy flexibility curves provides good results for the mean absolute percentage error (MAPE), which is just above 6%, allowing for safe DC participation in DR programs.