Counteract preceding rotations

In a situation where I have two axis adjacent back to back (let's say a robotic arm) I can sometimes perform two rotations ($R_1, R_2$) such that the resulting position and direction is unchanged.

This is trivial in cases where two axis are identical -- having $R_2 = -R_1$.

In case the axis are orthogonal, there is no solution.

Third case being in between the two, where there is not a solution, but there is a "best" fit.

A more complex situation is having $~15$ of these axis.

What is the proper name for this concatenated rotation (so I can search better) and how would one model a counter rotation? I envision an algorithm along these lines, but I'd like a closed form solution:

For rotations $i$ through $j$

1. Let $k$ = $j$
2. Find best fit rotation for $k$..$j$
3. If this is not a $0$-error solution
• Set $k$ = $k - 1$
• Goto #2

Achieving cumulative rotation of identity is a simplified version. This is more complex because rotations do not start at the same origin. They are concatenated -- so in real world a robot's arm of $15$ degrees of freedom, with each rod being, say, $12$ inches, may collide and prevent the rotation. I'm not worried about this collision for theory purposes.
Counter, as in "undo a rotation"? Note that rotation matrices are orthogonal ($\mathbf Q^T=\mathbf Q^{-1}$)... – J. M. Sep 2 '11 at 16:03