"Compress" a transform hierarchy
This is non-trivial.  For an arbitrary animation, you would basically have to evaluate the data_paths at every frame and insert a keyframe.  For a rotating cube you would have to give it both rotation and location keyframes.

For an example of how sticky this can become, consider the similar http://web.purplefrog.com/~thoth/blender/python-cookbook/snapshot-keyframes-as-mesh.html, which I do not include inline because it does not actually solve your problem, it is just an example of how things can get messy when you have to step frame by frame and coerce blender to apply (for lack of a better word:) stuff.

For the special case of rotations, you can use sinusoidal easing (on the t menu of the fcurves editor) to animate the location of the cube as long as it always rotates in 90 degree sweeps.

Another trick for the limited case would be to change the origin of the cube's mesh to be where the empty used to be and then rotate the cube.