A General Approach to Energy Optimization of Hybrid Electric Vehicles