Making full use of front road grade information to achieve the best fuel efficiency is important for intelligent vehicles. Normal theoretical studies pay too much attention to engine continuous feedback control. The theoretical foundation of switching between traction and brake control has been ignored. In mountainous terrain, both the engine and road slopes are energy sources. Switching between traction and brake control is the key point. This research focuses on broadening the normal control range. The comprehensive objective function that contains traction and brake control is built, and then the analytical switching control law is derived based on Pontryagin's maximum principle (PMP). Analytical switching control laws express the mechanism of switching between traction and brake control for economic cruise control (ECC). Simulation results show that the model can solve the switch time and the entire speed profile precisely. Brake control is very important in downhill situations. The parameters in the objective function influence not only the switch time but also the switch process. This research offers a theoretical foundation for ECC with road slopes and can make onboard control more precise and efficient.