Cycling uphill on a road - sitting or standing on pedals?
You're most efficient sitting with a cadence between 80 - 100 (faster if you can do it) so it's recommended that you stay seated as much as possible. For mountain biking staying seated increases the weight on your rear tire and reduces the chances of it slipping as long as you can keep a smooth spin stroke and not 'mash' the pedals on the down stroke.

Standing is harder on your body but in long climbs it's great to switch it up so that you move some of the force around your muscles and give them a break. Standing is also great to get you up that 'really steep' part of a climb or to sprint over the top and lose your friends (or win a race). 

As stated above stay seated with a high cadence for as long as possible. Switch up to standing as needed to give yourself a break or an extra boost of power.