Facilitating workload consolidation and improving server utilization are critical for reducing cost and improving energy-efficiency of modern datacenters. One major challenge for improving utilization is to do so without affecting the quality of service (QoS). On modern servers, various co-located jobs may share critical resources including 1) micro-architectural resources such as last level cache, memory bandwidth, and functional units, etc., and 2) energy resources including grid power and distributed batteries that provide an additional power source especially during high load period. Multiple co-located jobs may contend for shared these resources, causing interference, threatening application QoS or even triggering the circuit breaker and resulting in costly downtime and severe QoS violations. This project addresses these challenges by designing a cross-layer system that effectively manages workload consolidation, quality of service (QoS) and various energy sources to optimize for energy efficient computing. Our system spans several layers, including profiler, static compiler, online lightweight monitoring and prediction, runtime execution management, hardware power state control and energy sources control. The compilation technique identifies and inserts markers in contentious code regions in low-priority applications, as well as critical regions in high-priority applications that require QoS protection. The lightweight runtime utilizes the compiler hints, monitors the QoS, power consumption, etc., and adaptively adjusts the pressure applications generate to the shared resources such as shared cache and memory bandwidth, manages battery (dis) charges and hardware power states to guarantee QoS and achieve efficient power shaving.