The February Trends in Genetics has a nice write-up of the evolution of alcohol production by yeast. Modern fermentation relies on the yeast metabolizing 6-carbon sugars but choosing to halt at the 2-carbon stage (like ethanol) rather than completing the process by going all the way to carbon dioxide. This is a loss of potential energy for the yeast-- even though it's a happy outcome for humans!-- so it's interesting to understand the natural selection events which favored this stopping short behavior.
Ethanol is metabolically a dead-end molecule, but it's a single enzymatic step away from the more central 2-carbon relative, acetaldehyde. The enzyme involved, alcohol dehydrogenase (ADH), can shuttle 2-carbon molecules back and forth between these two configurations, so it could have emerged during evolution either to gather in ethanol as a fuel source, or as a way to make ethanol from acetylaldehyde (think of a deserted railroad track where you're not quite sure which direction the trains run).
Evolutionary analysis suggests that ADH was initially used to make ethanol, suggesting that ethanol itself is useful to the cell. The current theory is that ethanol helps keep competitors away. Ethanol is toxic to other competing microbes, so-- as long as it's not needed for fuel-- the yeast can make enough ethanol to poison the waters for competitors. Later, when sugars run out, it can reel the ethanol back in and use it as a secondary fuel.
There's also a suggestion from molecular clock data that this ability to accumulate ethanol was favored soon after the emergence (50-100 million years ago) of fruiting trees. The six-carbon sugars which are the basis for modern fermentation became widely available then, so several yeasts jumped on the opportunity and evolved new ways of controlling their metabolism to generate this useful by-product.