Most of my vehicles I buy new so it's just a matter of keeping them cleaned up.
One thing that has worked good for me on any used vehicles I have purchased is to try to get an another area cleaned up each time you clean the car. It doesn't seem quite so daunting a task when you break it down into sections. Maybe work the valve cover area one time, do the painted panels the next. Just clean a dirty part that you haven't done before. Before you know it, the whole underhood area looks good.
To keep them clean, I wipe it down every time I wash the exterior. Quite often I will actually wash the engine compartment with car wash shampoo, just rinse with a very light spray, wipe everything down with an old towel. If you are concerned about electrical components, cover them with some plastic wrap. I don't spray directly on any electrical parts and don't cover anything. One van I had for 14 years and had no problem doing it that way.