Often, a green apple flavor is caused by a fermentation by-product called acetaldehyde. If you let it age in the primary for another month or two, the flavor should dissipate (the yeast actually continue working even though there is no visible sign of fermentation, and they turn the acetaldehyde into ethanol, as I understand it).
It develops, usually, because of some reason associated with the yeast. Make sure you are using a high quality yeast. Make sure you are pitching enough yeast (make a starter if you are using liquid yeast, or use dry yeast). Oxygenate the wort before adding the yeast (shaking it up madly will do the job). Finally, make sure the temps are in the low to high 60s for ale yeast.