what is function of z-axis in accelerometer?
I assume you are asking why one would need a 3-axis accelerometer rather than just 2-axis? Well it depends what you need to measure - 3-axis is fully general and basically measures the acceleration vector directly. For something moving in 3 dimensions (such as an UAV/drone/multicopter/RC-plane) its very important to know the acceleration vector.
For a tilt-sensor one can assume its only the acceleration due to gravity that matters, which has a fixed amplitude, so that direction of tilt can be inferred from just a single axis (or two for x-y-tilt).
Another important feature of a 3-axis accelerometer is that you don't have to place in any particular orientation, since you can tweak the software to swap axes - so you aren't constrained to having your circuit board in a fixed orientation within the device - useful if you are developing an OEM module for instance and you don't know where the module will end up.