Rigid Body and directional constraints
You can do this with Rigid Body Constraints.
The 'Generic' constraint allows you to set up the constrains between two objects to set the amount the objects are allowed to vary from an Angular (rotation) and a Linear (position) point of view. By linking your 'Active' Rigid Body object to a 'Passive' one (that acts as the anchor) you can easily limit the motion.
The settings I used were as follows :

Here the limits on X and Y prevent it from moving in anything but the Z direction and the limits on Angle prevent it being rotated. Note how each is enable/disabled and the Lower and Upper limits set. In my case the Cube was the Active body and Sphere was passive to act as the anchor to it.
To set this up, simply select the two rigid bodies and select the Connect option, specifying to connect as contraint type 'Generic', then select the created empty and setup the constraint as shown above.