It is fairly well established that (at least in western countries) people have these unrealistic positive self-favoring views:
Furthermore, it seems that these illusions are associated with mental health. See Illusion and Well-Being. It may be that these tendencies are less pronounced or absent in some cultures (see Is there a Universal Need for Positive Self-Regard?.) There is also some reason for methodological concern due to the heavy reliance on asking people to compare themselves to others in this literature (see Biases in Social Comparative Judgments.) Also, it may be possible to be mentally healthy without positive illusions, but this rare, perhaps because it requires a great deal of effort to achieve this perspective.
It is an interesting question why this bias exists. First of all, why isn't this illusion harmful? Shouldn't this bias lead people to make bad decisions that would be avoided by unbiased analysis? If the bias were harmful we would expect it to be selected away, regardless of whether it is a biological behavioral tendency or a cultural construct. Also, even if the harm is less than one might suppose, there must be some practical benefit of this bias that overwhelms the negative effect.
The evidence on the harmfulness of positive illusion is mixed. There is considerable evidence that unwarranted optimism is a major factor in leading to bad decisions: business, medical or political (see Optimism bias), however there seems to be considerable Retrospective bias here—unreasonable optimism has undoubtedly contributed to most successful decisions as well.
There is also evidence that positive illusion varies according to the situation in ways that reduce the harm. Most significantly, Effects of Mindset on Positive Illusions argues that when we debate a difficult problem the bias largely disappears. Interestingly, it also seems that positive bias is generally enhanced when we are pursuing a goal already decided on, which suggests that the benefit of positive illusions may be in aiding motivation during the implementation of the decision. Also, there seems to be consistent time variation in optimism, with optimism being high for future events, but decreasing as the moment of truth approaches, then once again increasing as the event passes.
The most obvious payoff from positive illusions is that they can directly make us feel good. This payoff provides a motivation to believe things that are unrealistically positive, and this motivation may distort our perceptions. Whether Positive Illusions are “motivated” or not has been a substantial controversy in social psychology. A belief is said to be “motivated” if we believe it because the belief is in some way desirable or psychologically helpful rather than because it is true. In social psychology it seems that the general assumption is that positive illusions are motivated by the desire to maintain a positive self-image and self-esteem, though if the belief is adopted because it is socially approved or socially helpful it would also be “motivated.”
A somewhat similar psychological explanation is that positive illusions are necessary for mental health, and the need for emotional regulation outweighs the negative effects. The psychological explanation that optimism is needed to avoid depression is unsatisfactory because it begs the question of why our minds work this way. In fact, a much more convincing evolutionary explanation relating optimism and depression reverses the direction of causation, saying that the purpose of depression is to reduce optimism when things aren't going well (and a change in direction may be necessary.) It is plausible that realism is particularly valuable when change is needed, but this doesn't explain why optimism is the correct default for normal situations.
You could argue that for unknown functional reasons positive illusions are just as necessary to mental functioning as positive blood pressure is to physiological functioning—it is a contingent fact of the way the brain works rather than an adaptation in the evolutionary sense. However, we feel that it is fruitful to pursue the Evolutionary Psychology approach of suspecting that mental phenomena have some practical benefit in terms of survival and reproduction.
Perhaps we have positive illusions because these beliefs give social benefits. The most common social explanation (favored by sociologists and evolutionary psychologists) is that positive illusions are are socially self-serving because they aid in Impression management and persuasion. It is easier to argue that we are superior or deserving if we believe it ourselves. The belief that we are more virtuous than others is particularly suspect in this regard, however believing that you are virtuous might help you in behaving virtuously.
Is there a Universal Need for Positive Self-Regard? offers an intriguing hybrid explanation—positive illusions are prevalent in western culture because they are indirectly reinforced by western cultural values emphasizing the importance of independence, confidence and personal happiness. These illusions help westerners to function in their culture because they support culturally desired characteristics.
Perhaps positive illusions lead to more beneficial behavior than harmful behavior. Optimists persist longer in problem-solving than pessimists. For example, optimists persist twice as long in trying to solve an insoluble puzzle. This is intuitive, but why is generalized persistence good? After all, in the puzzle experiment, the optimists were only wasting their time (because the puzzle was insoluble.) Persistence is good because Prediction is Intractable; in the real world (as in the experiment) you have no idea whether a significant undertaking is possible or not. You've got to make your best guess about whether this is a good course, then stick with it until either you succeed or repeated failure leads you to conclude that it is difficult, perhaps impossible. Positive illusions are clearly related to cognitive biases concerning the future and planning such as Sunk Costs and the incorrigible human failure to learn from the failure of past predictions (see Prediction is Intractable).