Energy analysis and optimization