David you are right that there are ways to do it. Actually it is ok to do if you are careful but your local real estate tax exemption is key to preserve. You just need to account for it properly, and be clear about it in your filings with the IRS. Many churches lease out their steeples for cellphone towers, and often a parish hall is leased for events. Another source of income is a rector’s house or clergy house, which is not being used but can be leased out. I am not an expert, consult a local real estate attorney and CPA for guidance.
From what I understand, each jurisdiction handles these exemptions differently.
Churches often lease out their Sunday schools for for-profit preschools during the week. A museum has a gift shop, of course. Colonial Williamsburg used to separate out its for-profit operations, as I recall, including hotel and retail.
In the UK, the whole Virgin company from Richard Branson started in a church basement. The rector took inspiration from a kid wanting to sell records, and an empire began.