In this work, we first study and then propose an optimal version on the medium access control mechanism known as carrier sense multiple access with collision avoidance (CSMA/CA). This protocol is adopted by many wireless communication standards, such as the IEEE 802.11 series and IEEE 802.15.4 (ZigBee). We first identify its drawbacks in a slow fading channel environment, and show that the CSMA/CA can be very energy-inefficient, especially in many wireless sensor network (WSN) applications where the traffic demand is low. In particular, we study communication over a Rayleigh fading channel, which we model by means of a time invariant Markov process. We then show that the decision regarding the optimal access time on such a channel can be formulated as an optimization problem, and that an optimal solution can be accurately derived. We also simulate a ZigBee node in a Rayleigh fading environment and the result shows that optimum channel access can save significant amount of energy compared to conventional CSMA/CA.