Arduino program occasionally stops running.

Do you power the relays from the Arduino's 5V pin?

If so, the regulator that converts 12V to 5V is probably overheating and shuts down.

Solution in that case is a separate power supply for the relays.