Barnsley and his collaborators propose that parrots produce different mixtures of psittacofulvin chromophores during feather growth, and release these molecules into the growing feather at different times and at different concentrations to produce magenta, red, orange and yellow coloration and color patterns.
They are used to attract possible mates. Colors and patterns help birds identify their own species. Colors can help birds hide from predators by camouflaging them. Colors are used to attract attention when courting (ie: courtship displays).
Blue birds are not really blue. They do not have any blue pigment. Instead they use a very cool trick called light scattering. It is somewhat similar to how a prism works.
The predominant colour of plumage in parrots is green, though most species have some red or another colour in small quantities. Cockatoos, however, are predominately black or white with some red, pink, or yellow.