Regulation of gene expression and protein synthesis occur on multiple levels, and together these levels allow for fine control of when, and to what extent genes are active. It would be impossible to give a comprehensive answer for such a broad question. Here is a starter, beginning with the most important fact:
DNA is used as a template to make messenger RNA, which is exported out of the nucleus to produce proteins on structures called ribosomes in the cytoplasm.
One the level of DNA, there is a lot of regulation of which genes, and when, and to what extent, will be transcribed into messenger RNA. The name for this regulation is transcriptional regulation. For example, a network of proteins called transcription factors bind to DNA, regulating a gene's accessibility to transcriptional enzymes. Another example: the three-dimensional topography of DNA is also important. Epigenetic features may render some stretches of DNA inaccessible. The specific action of distal elements called enhancers can also affect a gene's level of expression. There are many things working in tandem on this level.
Once a messenger RNA is formed, it has to be exported out into the cell from the nucleus. In the cytoplasm it can be packaged, isolated from being translated into protein, degraded, accumulated, the list goes on. This is called translational regulation. Currently, there is a lot of focus in biomedical and basic research on microRNAs, which are RNA species which participate in regulating the amounts of messenger RNAs present in the cell. They are also found in the nucleus. Many biotechnologies are based on this concept; also, a common lab practice is to knock-down (reduce the expression of) genes of research interest by a technique called RNA interference.
Additionally, there's regulation of protein biosynthesis at the ribosome, which often complexes with other molecules in complicated ways to ensure an additional layer of tuning of how much protein is produced, and how quickly.
There are many, many other known levels of regulation. There also remain many unknown mechanisms of regulation, which scientists are busy with uncovering and understanding as we speak.
EDIT: What dictates which protein to synthesize at a given time? The history and present identity of a cell. By identity, I mean its state regarding regulation of its own gene expression, as well as other things.