Inertial Measurement Units (IMUs) are increasingly used for human motion analysis. However, two major challenges remain: First, one must know precisely in which orientation the sensor is attached to the respective body segment. This is commonly achieved by accurate manual placement of the sensors or by letting the subject perform tedious calibration movements. Second, standard methods for inertial motion analysis rely on a homogeneous magnetic field, which is rarely found in indoor environments. To address both challenges, we introduce an automatic calibration method for joints with two degrees of freedom such as the combined radioulnar and elbow joint. While the user performs arbitrary movements, the method automatically identifies the sensor-to-segment orientations by exploiting the kinematic constraints of the joint. Simultaneously, the method identifies and compensates the influence of magnetic disturbances on the sensor orientation quaternions and the joint angles. In experimental trials, we obtain angles that agree well with reference values from optical motion capture. We conclude that the proposed method overcomes mounting and calibration restrictions and improves measurement accuracy in indoor environments. It therefore improves the practical usability of IMUs for many medical applications.