Abstract The huge energy consumption of datacenters providing cloud services over the Internet has motivated different studies regarding cost savings in datacenters. Since energy expenditure is a predominant part of the total operational expenditures for datacenter operators, energy aware policies for minimizing datacenters’ energy consumption try to minimize energy costs while guaranteeing a certain quality of experience (QoE). Federated datacenters can take advantage of its geographically distributed infrastructure by managing appropriately the green energy resources available in each datacenter at a given time, in combination with workload consolidation and virtual machine migration policies. In this scenario, inter-datacenter networks play an important role and communications cost must be considered when minimizing operational expenditures. In this work we tackle the Elastic Operations in Federated Datacenter for Performance and Cost Optimization (ELFADO) problem for scheduling workload orchestrating federated datacenters. Two approaches, distributed and centralized, are studied and integer linear programming (ILP) formulations and heuristics are provided. Using those heuristics, we analyze cost savings with respect to a fixed workload placement. For the sake of a compelling analysis, exhaustive simulation experiments are carried out considering realistic scenarios. Results show that the centralized ELFADO approach can save up to 52% of energy cost and more than 44% when communication costs are also considered.