Assuming you already know which cubes are adjacent, you can:
Throw all 12 (if they have shared vertices) or 16 (if not) vertices into a collection
Find the extents and center of the collection
Remove the original cubes from your index list
Calculate the maximum dimension from the extents you already found
Add 8 new vertices to define the new cube centered at the center you already calculated
Add the indices connecting those vertices to your index lists
If you're looking for coplanar faces that can be removed to create rectangular prisms (to remove hidden faces), just zip through your index list and find pairs of triangles that use the same vertices, though probably in opposite order (clockwise vs counter clockwise), and remove both triangles assuming they face each other.
@BjornWesen's comment is correct in that this can be overkill unless your mesh is pretty complex.
However, removing unnecessary faces potentially saves a lot of time in the pixel shader. Any time you draw multiple primitives in back-to-front order (typically a function of your camera location relative to the mesh), each primitive must be rendered, then overwritten or discarded (based on depth comparison) by any closer primitives when their turn comes. Obviously this takes unnecessary time which could be used for other things.
In short, if you feel that any performance issues you're seeing may be due to overdraw, I think this is a good place to start looking. (The profiler is your friend! Don't assume you know where your bottleneck is unless it's written in 40 foot (12.2 meter) flaming letters in your mind.