Why does the earth spin?
Conservation of angular momentum.
Any mass which rotates around a point has angular momentum, the tendency for an object to continue its state of rotation. Like any other form of momentum, angular momentum must be conserved in a closed system.
Currently, the most accepted theory of the formation of the solar system is that a nebula collapsed to form the sun, planets, and other bodies in the system. Initially this nebula was made up of a bunch of gas and dust particles, each with their own random motion.
As gravity collapsed the nebula in on itself, collisions between particles averaged the motion of the particles out, and the cloud began to rotate and form a disk. The denser that the disk became, the faster it spun, due to the conservation of angular momentum.
Most of the mass collapsed into the center and became the sun. The rest condensed into the planets and other objects that orbit the sun. Since the planets were formed out of a rotating disk, they themselves rotate, and due to conservation of angular momentum, they continue to rotate today.
A top down view of the solar system would show that most rotations in the solar system are counter clockwise. This includes the rotation of the sun and planets, the directions of the planets' orbits, and orbits of moons around their planets. Notable exceptions include Venus, which rotates backwards, and Uranus, which is tipped over on its side.