How to "Merge" a Mesh
You basically want to separate each shell into its own object, and then boolean all the objects together.

To do this quickly:


Select everything in Edit Mode
P > Separate by Loose Parts
Enable the Bool Tool add-on (included with blender by default)
Select all the objects in Object Mode
Click the Auto Boolean > Union button in the Bool Tool panel:




You may want to triangulate the mesh in edit mode (Ctrl-T) afterward to make more sense of it.