Here is some good information I found:
The most fundamental thing to understand is that no group and no church is “owed” a tax exemption. These exemptions on various taxes are in no way protected by the Constitution — they are created by the legislatures, regulated by the legislatures, and can be taken away by the legislatures. At the same time, tax exemptions — including those for religious groups — are not prohibited by the Constitution.
...The only restriction on how the legislatures act when it comes to creating and giving out tax exemptions is that they are not permitted to do so based upon preferences for content or based upon a group’s failure to take certain oaths. In other words, once tax exemptions are created at all, the process for allowing certain groups to take advantage of them is restricted by constitutional rights.
In particular, they cannot give exemptions to a group merely because the group is religious, and they cannot take away exemptions for the same reason. If tax exemptions are created for magazines or books or whatever, the exemptions must be available to all parties, not just religious and not just secular applicants.
http://atheism.about.com/od/churchestaxexemptions/a/overview.htm
The tax exemption isn't just for religions. Here are the legal requirements:
Exempt Purposes - Internal Revenue Code Section 501(c)(3)
The exempt purposes set forth in section 501(c)(3) are charitable, religious, educational, scientific, literary, testing for public safety, fostering national or international amateur sports competition, and preventing cruelty to children or animals. The term charitable is used in its generally accepted legal sense and includes relief of the poor, the distressed, or the underprivileged; advancement of religion; advancement of education or science; erecting or maintaining public buildings, monuments, or works; lessening the burdens of government; lessening neighborhood tensions; eliminating prejudice and discrimination; defending human and civil rights secured by law; and combating community deterioration and juvenile delinquency.
http://www.irs.gov/charities/charitable/article/0,,id=96099,00.html