The most environmentally friendly is probably going to be a heat-pump based electric water heater. They are more efficient, because it takes less energy to move heat from in your house into the water than it does to create heat in the water. The problem is they are more complex and more expensive than either gas or electric water heaters.
Most things I hear in the last decade or so do not like tankless water heaters from an energy use perspective. I’m not sure exactly why, except that keeping the water hot in a modern hot water heater does not take very much energy at all.
The dirty air problem with gas stoves is because they vent into the house. A gas water heater will send exhaust gases out a chimney. In my case, one shared with the furnace.
If you go electric and pay time of use rates, then you can do like in the video below. He only lets his water heater turn on when electricity is cheap, and just uses from the tank the rest of the time. That only makes sense if it’s automated, and your daytime hot water use is low enough.
Whatever you do, a lesson I learned when replacing mine a couple years ago is know what rebates and stuff are available. I few different plumbers wanted to install regular gas water heaters that didn’t qualify for any rebates. Upgrading to a more efficient heater that did qualify was too expensive to make sense when going through a plumbing company, because they only stocked low end and very high end models.
Then I shopped for water heaters at Home Depot and Lowes. There the price difference between low end and high efficiency was about the amount of the rebate, so I could upgrade to a high efficiency heater for free, and pay less to use it going forward. The store just contracted installation with one of the local plumbing companies. In the end I paid about the same amount as I would have for a basic heater from a plumber, but instead got one that costs me less to run.
The only downside was the particular heater I picked needed to be shipped to the store, so it took an extra week. Not a problem as my old worked, it just was 20 years old and leaking.
One last thing, if you do shop at the chain hardware stores, the price of the exact same model water heater was different at different locations in the same chain. That’s why I went with ship to store, because the store a few miles away that had it in stock wanted $150 more.