We study the dynamic energy optimization problem in data centers. We formulate and solve the following offline problem: given a set of jobs to process, where the jobs are characterized by arrival instances, required processing time, and completion deadlines, and given the energy requirements of switching servers ON or OFF, in which time-slot which server has to be assigned to which job; and in which time-slot which server has to be switched ON or OFF, so that the total energy is optimal for some time horizon. We formulate the offline problem as a binary integer program that can be considered as a new version of generalized assignment problem which includes new constraints stemming from deadline characteristics of jobs and the activation energy of servers. We propose an online algorithm that solves the problem heuristically, and we compare it to random assignment solution. Index Terms-job scheduling, data centers, deadline-aware energy management, generalized assignment problem, online algorithm.