Generalized spin-Hamiltonian for paramagnetic ions in crystals. I. General formalism and its application to cubic crystalline symmetry