Check your grounds and battery as stated, and test the crank sensor (I think there's a way to test them with a multimeter).
If those aren't it, then I'd bet it has to do with your ignition switch or cylinder, whatever it's called. The thing you put your key into. My gauges would randomly stop working for a while and I'm almost certain it's corroded connections in my ignition switch.