Making Undo/Redo function laregly depends on how you want to track theese changes.
If you are tracking changes for each cube seperately then I would suggest creating dynamical array of special records which will contain cube position, old and new state of it.
If you are tracking changes of several cubes at once (making cube shaped hole in your terrain) then I you can euther use similar system as above with the only difference that you now have seperate arrays for each undo/redo action. Or you can create some kind of submaps (array smaller than the whole map array) which will store previus state of the map section before it was changed.