Acceleration in the Z direction in Earth frame regardless of orientation
To subtract the acceleration that counteracts gravity, you need to know your current orientation (i.e. you need a six axis accelerometer). Then the problem reduces to subtracting a vector of length \$9.81\frac{\textrm{m}}{\textrm{s}^2}\$ in the appropriate direction (and realistically, you also need to determine the gain and offset errors for each axis sensor, but a highpass filter will probably do for most applications).

Without knowing your orientation, no solution is possible, because the problem is under-defined.