@yd14, to change the direction of the Z motor, find the M569 P2 command in config.g and change S0 to S1 or vice versa.
The other problem is likely to be caused by incorrect endstop switch configuration. Test the endstop switches as described at https://duet3d.dozuki.com/Wiki/Connecting_endstop_switches#Section_Test_endstop_switches.