I have done all kinds of tricks and gags to get upgraded (..I know, I'm ashamed of myself) when I think that there is a reasonable possibility that I could get one. There is no magic formula but you can try different things. First of all, I have yet to come accross an airline or flight in which I got upgraded when there were still seats available in the class I paid for, complimentary upgrades are most commonly doled out on overbooked flights to accomodate as many as possible.
A few things help: dressing well (no slippers and shorts), being polite (do not beg or demand upgrades, agents have heard it all before, they'd rather you just be polite and honest), be friendly to gate staff.
membership helps as does premium membership, especially in the US, other airlines do not necessarily go through the protocol of FF
membership status of handing out upgrades especially when they are frantically trying to close a flight.
My 'modus operandi' has been to walk up to the counter (if you're male, go to a female check-in agent), and be courteous, polite and friendly, make a little small talk or say something funny to break the ice to have a short but friendly conversation with the agent. Then ask "Is the flight completely full"?, if she says no, then ask "You wouldn't be looking to upgrade any passengers on todays flight will you?" Often they will say no, but on odd occasions after I have been able to humour the agent, they still upgraded me.
If to the first question she replies "Yes sir, we are overbooked today", then you are in luck. They will be looking to upgrade passengers from Y to C and from C to F to accomodate as many as they can before they start denying boarding to passengers turning up late to check-in. Then, using your best charm say this line, "I know you are not obliged to help me, however if I may so ask, could you please consider me for an upgrade if at all you are looking to upgrade any passengers on todays flight?". It works folks! 70% of the time when I have been in this situation they say "I'll see what I can do" and put me on the UPG list, either they give me my boarding pass straight away or at the gate.
I have a friend who worked as a check-in agent for many years, she said that she would be most likely to give UPG's to those passengers who were most polite and nice. Its a human business after all and you have to use your charm.