How do I change a single-pole switch to a timer with 4 wires?
You should read the instructions included with the new switch.  You'll likely find that the black wire is an ungrounded (hot) wire, the white is a grounded (neutral), and the red is the switched "hot" wire. 

If there are only two wires coming into the box, you won't be able to connect the timer. The timer requires a grounded (neutral) connection, which is not present in a typical switch loop.

As for the ground wire. If the metal box is grounded, you can connect the ground from the switch to the box. You can connect the ground using a ground screw and the threaded hole in the back of the box, or using a ground clip.