Accelerometer - accounting for gravity for arbitrary device angle

How do you subtract gravity from accelerometer results, for the device being moved at anytime to an arbitrary angle?

Not completely sure, but I think you are supposed to look at the gyroscope and subtract gyroscope.gravity. I’m working ont he same problem right now.