When cycling uphill on a road, what are the pros and cons of cycling while standing up on pedal versus sitting on saddle?
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.
curtismchale's answer is spot-on -- I'm only answering to quote from my favourite cycling article "On the Technique of Climbing" by Luis Bernhardt:
When you are sitting in the saddle, you are basically on a Universal Gym. The way you fit the bike prescribes how efficient you are.
Seated climbing is the most efficient way to go: just pick a low enough gear and spin it out. Standing requires proper technique and can never be as efficient since your muscles have to support your entire body weight. But standing does change the muscles in play and can be a nice break from that uncomfortable saddle. It also might be your only option if you don't have low enough gearing to spin up a steep hill.
Effectively what you are doing when you stand on the pedals and rock the bike from side to side is lowering the crank length and reducing the gear ratio. You are also using a lot of energy to hold the bike stable while you change from side to side & as well as wasting energy through the extra flexing of the frame, cranks & pedals. The only situations that really warrant getting out of the saddle is to either give your muscles a chance to rest by using a slightly different set or to accelerate very quickly, such as coming out of a corner in a race.
I don't agree that seated pedaling is better since standing exerts a higher weight (effectively all your body weight) on the pedal. The link below explains it better: https://www.bikejames.com/strength/why-this-video-shows-that-standing-pedaling-really-is-better-than-seated-pedaling/
I agree that your cadence is lower but if you have more torque (due to larger weight on the pedal) you can shift to a higher gear. I also agree that your balance is in jeopardy (I fell once while biking standing) so I suppose don't stand up unless you have good balance and you can spare some energy to balance yourself. Personally I bike standing only on a tricycle since it needs no energy to balance it but that's another story.