There seems to be a misconception at the driving part of the question. Exercise has more effects (on the brain) than just stimulating a few synapses. That is indeed a vague and vastly incomplete conception. Since brain chemistry is by far not completely understood it is also quite premature to believe we would be able to define some kind of "optimal" endorphine production. These neuropeptides are short acting and produced and released, signalling and reabsorbed as needed. Endorphins are quickly broken down by proteases. So what we do know to directly answer the question: not long.
What we do know about the brain from pharmacology and neuroscience is that it is not operating and optimisable like a belt-fed machine gun when it comes to releasing transmitters. This system strives over-all for a certain kind of balance, equilibrium or homeostasis. You regulate one thing up, the brain regulates this down again. Flood the brain with nicotine, that stimulates or blocks certain receptors, which in turn are altered in their number to compensate for this over the top supply. This does not mean the neurochemistry cannot be influenced.
Exercise can make you feel good. But that feeling does not depend on endorphines alone:
While endocannabinoids seem to contribute to the motivational aspects of voluntary running in rodents, influencing the total distance covered most likely via CB1 receptors, they are less involved in the long-term changes of emotional behavior induced by voluntary exercise.
As usual human behaviour and experience is more than just some biochemicals floating around. Any human is much more than the collection of some neurotransmitters and more than the sum of some electricity circuits:
Dissociating runners use a cognitive style in which they cut themselves off from the sensory feedback they would normally receive from their body. Marathon runners demonstrated high hypnotic susceptibility scores. Additionally, use of dissociation as a running strategy during the marathon was positively related to susceptibility, and runners who dissociated in training had higher susceptibility scores than did other runners. Runner's high was not related to hypnotic susceptibility; however, it was positively related to dissociation. The most common description of runner's high was general relaxation, whereas the least used description was total euphoria. Surprisingly some runners defined runner's high in ambivalent or negative terms. These results were related to the processes of self-hypnosis and to the positive mental health benefits of running.
Trying to use this exercise related 'legal high' sounds like a natural substitute. And of course, natural means safe:
Endurance athletes: physiologic changes and nonorthopedic problems.
The current increased participation in long distance running and endurance events brings new challenges to the physician. Adaptive changes of exercise must be differentiated from disease states. Left ventricular hypertrophy, Wenckebach rhythm, elevated creatine kinase (myocardial fraction), gastrointestinal bleeding, hematuria, hemoglobinuria, amenorrhea, and apparent anemia may all be exercise related. New syndromes have arisen--from "runner's high" to athletic amenorrhea. These dedicated athletes can be difficult patients. They are highly motivated and will continue training despite significant pain and danger of permanent damage. Speaking their language--carbohydrate loading, "the bonk," "slow twitch," "the wall"--is helpful in their treatment. Traditional health problems are less likely to bring the fitness addict to the physician than some new and peculiar disorders.
This is just to remind you that going after the maximal effect of endorphine related happiness through sports may lead to addictive behaviour that is not good at all. It is by no means to be read as an advice to abstain from sport, if you like it:
Does sport really produce positive effects in mental illness? The author discusses this question, through a survey of the literature. There is evidence that exercise increases endorphine levels. In order to support the prevention and treatment of depression through sport, it seems particularly useful, to encourage the practice of moderate, diversified physical activity.
Still looking to get a good dose of elevated endorphines (and a generally healthy mixup for your brain chemistry)? Then here is something that is more fun:
Social laughter is correlated with an elevated pain threshold.