Is tamoxifen effective only if the cancer has not spread outside of the breast?

On the Contrary. Tamoxifen is a very effective drug for the treatment of hormone-sensitive (estrogen receptor +) breast cancers that has spread outside the breast. It may be used alone or in combination with traditional IV chemotherapy, depending on the cancer stage. Furthermore, tamoxifen has been shown to be effective reducing the chance of developing breast cancer in high-risk women ("chemoprevention").
No. Tamoxifen affects cells throughout your whole body so it can treat breast cancer cells that are located anywhere in your body. It does not penetrate your brain very well, but works all other places. Additionally it can prevent your unaffected breast tissue from developing into a new breast cancer.