The traditional advice on cooking with wine, attributed to Julia Child, is that one shouldn't cook with wine one wouldn't like to drink, cresyd says on Chowhound. But that leaves a lot of room for dispute over which wines are drinkable, and which ones are "cookable."
Keep in mind that there's a big difference between genuinely foul-tasting wine—one that's corked or spoiled—and one that just isn't very good to begin with, bcc and sedimental both say. In either case, bad wine will impart its awfulness to food: Better to use it as fabric dye or a lure for fruit flies than to consume it, wyogal says.
For corked wine, though, there's a chance that if you bring it to a boil the taint could dissipate, bcc says. If so, feel free to cook with it; otherwise, don't. At the very least, you should like the taste of wine you cook with, cheap or not. HillJ would rather cook with a tasty balsamic vinegar than an untasty wine.
Inexpensive wine that tastes merely OK (i.e., not terribly complex or exciting) can be excellent for cooking, especially if wine isn't the focus of the dish. A risotto with six parts stock to one part wine won't suffer from mediocre wine, but a coq au vin, where the sauce is heavily wine-based, will definitely reflect the quality of the wine you pour in the pot, tastesgoodwhatisit says.
Leftover wine that isn't heavily oxidized can be used to deglaze pans, in marinades, or for poaching fruit. You can even turn it into vinegar, ipsedixit says. Isolda and jpr54_1 recommend poaching pears in vin ordinaire with sugar and spices. Mulling (warming wine and adding spices and a sweetener) is a good use for so-so wine, nokitchen says. So is sangría. In fact, there are many recipes, such as CHOW's Chardonnay Cover-Up, that creatively disguise not-so-great wines, and make them good to drink.