It is usually called "sensor fusion" there are tons of libraries out on the internet for it, basically it is subtracting the effect of one from the other, in your case it would be subtracting the acceleration of the motor * the calculated angle of the gyro from the accelerometer output.
The libraries basically put the accelerometer axis and the gyros rotation in the same space, so that rotation on the gyro rotates the output of the accelerometer to the same orientation, keeping things consistent over rotation, then when you have acceleration with no rotation it can be summed out, (a magnetometer would usually be added to provide a way to fight the drift of the gyro)