In "real life" you balance by turning the handle bars to move/ accelerate the contact point to the right or left of the center of gravity which causes the bike to rotate to the left or right. This is easier and more effective when moving because in addition to just moving the contact point to the right or left, you also accelerate to the right or left causing the vehicle to rotate to the left or right.
Example, riding along you turn the handle bars to the right - the contact point moves and accelerates to the right, the bike inertia lags and it tips to the left setting you up for a left turn. (This is why it is hard to learn how to ride a bike - do a search on "non-minimum phase").
You can do the same thing at a stop, but you have less control authority because the distance you can move the contact point is limited by the trail in the front suspension. But with practice, it can be done (up to a point...)
A simulation using a tool like Matlab / Simulink would go a long way towards figuring out your control algorithm.
http://www.mathworks.com/matlabcentral/fileexchange/27694-nxtbike-gs-self-balancing-bike-robot-by-steer-into-fall is an example of how to do it with Legos.
The "track stand" method helps with the control authority problem
track stand 101