Plastic bottlecaps are mostly compatible with each other because their threads conform to a standard called PCO 1810, or occasionally PCO 28, which is being gradually replaced by a newer standard called PCO 1881. These threads are formed into the bottleneck (called a “finish”) before the shape of the rest of the bottle is formed; companies like Jesper PET Preform will sell you the bottle “preform”, with the thread formed but the rest of the bottle uninflated; then it’s up to you to blow-mold the bottle into the shape you want.
The bottle caps (called “closures”) are sold separately, and they’re usually made of polypropylene (“PP”).
PCO 1881 has a slightly shorter neck (17mm instead of 21mm) and was finalized in 2009 by the International Society of Beverage Technologists. It apparently implies no loss in performance compared to the PCO-1810 standard, despite the steeper thread pitch and the threads going around only twice instead of the three times you see on PCO-1810 bottles.
Because the bottle neck and cap are so much thicker than the rest of the plastic bottle, they account for a substantial fraction of the material use in the bottle, so the 1.4 gram reduction due to the 4mm-shorter PCO-1881 standard amounts to 27% of the total weight of the PET bottle, not counting the cap.
ISBT has put the PCO-1810 standard and the PCO-1881 standard engineering drawings online along with their other standards, and “ippe” posted an STL file on Thingiverse that prints to a working PCO-1810 bottle closure at least in PLA on the Prusa Mendel I have access to. (You may want to turn that file upside down for printing if you want it to seal, though; the top was too long a horizontal span to cohere properly.)
In addition to the preforms, you can buy entire preblown bottles if you don't have blow molding (“pressure molding”) equipment; a 43-gram 1ℓ bottle costs around €0.36–€0.69 without the cap.