How to remove interior faces while keeping exterior faces untouched?

I plan to merge only cubes side by side yes. I have made a dungeon map using ROT.js and THREE.js together. I’ll try and make a link to show what I’m trying to achieve. If i can get this small example working i was planning to merge it with the bigger example. If they are removed then it’ll look like a dungeon once I set a viewpoint from inside.