I have logged thousands of kilometers with my mountain bike on the road. If all you are after are watts, this is a good solution. But you should keep a few things in mind: it is definitely less fun, because you are using the wrong tool for the job. After a while, I did compromise my mountain biking position in favor of being more aero (flipped the stem and slammed it).
On gravel I think a hardtail is definitely an option. You’ll feel quite comfortable, and there are gravel bikes (think steel frame) that are heavier than reasonably nice hardtails.
But if you are doing this because you are afraid of crashing, that won’t solve it. Knobbly tires can have less traction in corners on tarmac (depends on the tire, and there may be a transition). On tarmac a road bike or drop bar bike will still handle better. Plus, you can go slow on a road bike, too.