Beneteau and others routinely place their batteries in the same compartment as the engine... They also tend to install a fan that runs while the engine runs to help dissipate any fumes and some heat. That would also deal with any gassing off from wet cell batteries - so that would be a better place than under a berth, for instance.
1984 Fast/Nicholson 345 "FastForward"
".. there is much you could do at sea with common sense.. and very little you could do without it.."
Capt G E Ericson (from "The Cruel Sea" by Nicholas Monsarrat)