The fact that dream deprivation results in psychological disorders indicates quite strongly that dreaming serves a vital function, at least in higher functioning brains (ie: human rather than, say, rat). I have heard the suggestion that dreams are a sort of replay of the days events without our conscious brain restricting the associations made, it's suggested that this allows us to both reinforce those events into our memory and make connections between events that would otherwise be missed.
Alan