Virtual machine (VM) consolidation and switch/path consolidation are two typical techniques for improving energy efficiency in data centers (DCs). Most of existing work separately optimize VM consolidation and switch consolidation which results in inferiority of the optimization performance. Moreover, these work usually handle a user application as a VM flow (i.e., a source VM is connected to a destination VM). In practice, however, relation of VMs could be much more complex than the single flow and multiple VMs are connected via a network. In this work, we address a general DC energy optimization problem that enables tenants to express their applications by a general resource request graph (i.e., computation requests of VMs, bandwidth requests of VM communications, and time requests of VM execution). We propose a joint VM-switch consolidation (JVSC for short) algorithm to this problem. JVSC jointly optimizes the energy consumption of DCs in three steps: (i) it decreases the number of active PMs by VM consolidation; (ii) it decreases the number of active switches by switch consolidation at the tor tier, the aggregation tier and the core tier of the network, respectively; and (iii) it minimizes energy consumption of VM migration via an energy-aware migration strategy. Extensive experiments are conducted on both simulated applications and real Google cluster usage traces. Experimental results demonstrate that JVSC can save 60% around energy of DCs, compared to the state-of-the-art.