What determines the direction in which a moon/planet rotates within orbit around a planet/star?
Initially, it depends on which way the accretion disc rotates around the parent star. The planets that are formed from this will rotate in the same direction as the disc. However, some phenomena can disrupt these rotations, either the axial or even the orbital ones. Venus, for example, is thought to have suffered a massive collision which flipped it upside-down, since its axial rotation is retrograde. Moons depend on whether they are natural or captured, and on the effect the parent planet’s gravity has on them. Many captured moons have irregular or retrograde orbits and axial rotations (Saturn’s moon Hyperion is an example).