In accordance with General Laws c. 40A, and notwithstanding any provisions to the contrary, this bylaw shall not prohibit or restrict the use of land or structures for religious purposes or for educational purposes on land owned or leased by the commonwealth, or any of its agencies, subdivisions, or bodies political, or by a religious sect or denomination or by a nonprofit educational corporation.