Is there a cost to running the New York Stock Exchange? For example electricity costs, management costs, rents on the building(s). How do these costs (if any) affect the price of stocks sold on the exchange?
Yes, there's a cost to running the New York Stock Exchange. There's the premises, utility bills, staff, systems, and so on.
Yes, this affects the price of stocks on the exchange. The exchange recoups its fees, ultimately, from the companies listed on it, pushing up their costs.
However, for pretty much all companies listed on it, the stock exchange fees are a tiny part of their overall costs. Which means that the impact on the stock prices is pretty much negligible.
Stock exchanges do not own the stocks traded there. They are just like markets you buy your grocery from. Market stalls are rented out to traders and traders pay small fee/rent in return. Similarly, companies that list their stocks in exchanges (like NYSE and LSE) pay fees in return for having their stocks listed and traded. This has nothing to do with the prices of stocks that vary every second. The stock prices reflect the performance of the companies which issue them among other economic factors.
As to the cost of running exchanges, it really depends on the size of the exchange, you should get in touch with the NYSE for information about running it. Here you can find info about LSE registration and annual fees.