Internet energy consumption has increased rapidly, and energy conservation has become a significant issue that requires focused research efforts. The most promising solution is to identify the minimum power subsets within the network and shut down unnecessary network devices and links to satisfy traffic loads. Due to their distributed network control, implementing a centralized and coordinated strategy in traditional networks is challenging. Software-Defined Networking (SDN) is an emerging technology with dynamic, manageable, cost-effective, and adaptable solutions. SDN decouples network control and forwarding functions, allowing network control to be directly programmable, centralizing control with a global network view to manage power states. Nevertheless, it is crucial to develop efficient algorithms that leverage the centralized control of SDN to achieve maximum energy savings and consider peak traffic times. Traffic demand usually cannot be satisfied, even when all network devices are active. This work jointly addresses the routing of traffic flows and the assignment of SDN devices to these flows, called the Routing and Device Assignment (RDA) problem. It simultaneously seeks to minimize the network’s energy consumption and blocked traffic flows. For this approach, we develop an exact solution based on Mixed-Integer Linear Programming (MILP) as well as a metaheuristic based on a Genetic Algorithm (GA) that seeks to optimize both criteria by routing flows efficiently and suspending devices not used by the flows. Conducted simulations on traffic environment scenarios show up to 34% savings in overall energy consumption for the MILP and 33% savings achieved by the GA. These values are better than those obtained using competitive state-of-the-art strategies.