While there are still details to be hammered out, we have a reasonably good understanding for how the Solar System formed. A cloud of material began to collapse under its own gravity. Because the gas and dust particles in this cloud could bump into one another, they could exchange energy and angular momentum (important fact #1). Also, the cloud, even though it may have been close to spherical, likely contained some net angular momentum on the whole (important fact #2) - it is just unlikely that all the particles' motions would exactly cancel.
These two important facts, when taken together, mean the material is likely to settle into a disk. Particles whose angular momentum deviates from the average (by going in the wrong direction, by moving out of the preferred plane, by moving too fast in the right direction, etc.) will tend to be brought in line with everything else by these collisions. Gravity alone could accomplish this via dynamical friction, but collisions speed up the process so it occurs in reasonable time. Because important facts #1 and #2 are ubiquitous in so many astrophysical settings, many systems naturally form disks, for example galaxies.
The Sun, planets, moons, asteroids, and everything else then all formed from this disk, where everything was rotating with the same sense. As a result, most objects in the Solar System move in a plane, in the same direction. Furthermore, their spins are aligned the same way.
There are exceptions to this rule, but they are not common. They are interesting because they show the object in question does not have quite the same history as typical objects in the Solar System. Notable examples include:
Venus: While this planet moves around the Sun in the "correct" way, it spins "backward" (technical term: "retrograde"), albeit very slowly. We don't have any 100% agreed-upon theory, but this likely has to do with the gravitational tugs Venus has experienced from other bodies (most notably Earth) over billions of years.
Uranus: This planet is tilted, so its spin axis is way out of alignment with the orbital and spin axes you expect to find. In fact, it is "tipped over" by a bit more than 90∘, meaning technically it is spinning retrograde (if you had to choose only between "prograde" and "retrograde" to describe it). Again, the jury is still out on how this happened. Perhaps it was struck by a smaller planet in the earlier, more chaotic days of the Solar System. Alternatively, it may have been torqued by interactions with Neptune or other planets, a hypothesis that works well if the Nice model of the Solar System turns out to be correct, as this model predicts Uranus and Neptune swapped positions at some point.
Triton: One of the largest moons in the Solar System, Triton orbits Neptune in a retrograde fashion. As a result, the leading theory is that it did not form in situ with Neptune, but rather formed elsewhere and was captured by Neptunes's gravity. Even an object moving around the Sun in the "right" direction can end up orbiting a planet in the "wrong" direction, simply depending on which side of the planet it approaches from.