Pepsin is the active protein-digesting enzyme of the stomach. Pepsin acts on protein molecules by breaking the peptide bonds that hold the molecules together. Digestion of protein is completed in the small intestine by the pancreatic enzymes trypsin,chymotrypsin, and carboxypeptidase.
A pH of about 7 is the optimum and as the pH moves further away from the optimum pH the enzyme activity starts to slow down.
The short version is that parietal cells produce hydrochloric acid (as well as bicarbonate, to serve as a buffer). Nerves in the stomach sense the acidity and release acetycholine and gastrin to increase and decrease the amount of acid generated. There is also input from the brain, via the vagus nerve, which stimulates more acid when the stomach stretches (i.e. you're full).
advantages of ph are
food breakdown
killing bacteria
increases absorption of vitamins and nutritions