We study in detail the mechanisms causing dephasing of hyperfine coherences of cesium atoms confined by a far off-resonant standing wave optical dipole trap [S. Kuhr et al., Phys. Rev. Lett. 91, 213002 (2003)]. Using Ramsey spectroscopy and spin echo techniques, we measure the reversible and irreversible dephasing times of the ground state coherences. We present an analytical model to interpret the experimental data and identify the homogeneous and inhomogeneous dephasing mechanisms. Our scheme to prepare and detect the atomic hyperfine state is applied at the level of a single atom as well as for ensembles of up to 50 atoms.