This is less a recipe than a process. Carmelized onions are truly a magical thing - a extremely simple side dish, although not always so easy to pull off. Here are a few tips that I've noticed helps with the process.
First, make sure you have plenty of time. Carmelizing onions takes absolutely forever. It actually isn't a bad idea to prepare this while cooking other dishes - that way, you'll still be in the kitchen to stir the pot every now and then.
Start with an equal part of butter and olive oil, and turn the heat medium. After everything melts, put in the sliced onions. I like to use fairly large slices, because as things carmelize, everything shrinks like crazy.
The initial process of getting the onions soft takes a while. I sometimes cover the lid during this process, but usually just keep the heat on. Stir the pot from time to time to make sure that all the onions are getting soft.
Add a few pinches of salt and one pinch of sugar, to get the carmelization process going. At this point, the onions should be soft, and should be shimmering in the butter/oil mixture. Turn the heat lower, and just allow to continuously simmer.
For me, carmelizing onions usually takes the better part of two hours. Every 15-20 minutes or so, stir the pot to make sure there isn't anything stuck on the bottom.
As the process goes along, you may need to find that you need to stir more frequently. You want the onions to brown, but not burn.
Towards the end, add in a few splashes of balsimic vinegar to taste. This has two effects - one, even if not all of your onions are fully carmelized, it lends a nice dark color to the entire pot. And two, a bit of acid tastes wonderful with the sweetness of the onions.
And there you have it! A not-recipe that is guaranteed to go well with basically anything. I particularly like a bit of carmelized onions on the side of some rice or beans.