This is a problem that 3D animation software has to deal with all the time, namely when an object's coordinate system is related to another object's coordinate system rather than the global coordinate system. In the general case, there may be arbitrarily many such coordinate systems each adding their own pitch/yaw/roll to each child object.
The solution used by Blender (< is based on Quaternions. Wikipedia explains how quaternions work in this case: < That explanation is perhaps too lengthy to be copied here (though it can be if that's the only way to validly "answer" the question).