Sperm is produced within the testes.
Maturation of sperm cells occurs relatively slowly, over a (roughly) 74 day time frame in (human) males. Once a mature sperm cell is released into the lumen of a seminiferous tubule (within a testis) it traverses a series of ducts and tubules to eventually collect within the epididymis (normally located on the upper surface of the testis).
Sperm resides in the epididymis for an additional 12-14 days, where it undergoes a series of changes. It is within the epididymis that sperm normally become motile.
During erection, emission and ejaculation the sperm that has matured in the epididymis is normally expelled through the vas deferens and penile urethra. The seminal vesicle, prostate gland and bulbourethral gland add fluids (including semen) to the sperm that is expelled.