It appears most likely that you are suffering from the condition called Irritable Bowel Syndrome. It may present in different ways, one of the commonest ways is to present as a bloating and constipation. IBS is usually recurring, with periods of illness followed by periods of normalcy. It is an easily treatable condition, and will require some lifestyle changes, and specially some changes in your diet. You need to adopt a proper diet. Please look below for some sites which can give you some very useful tips on diet and other factors. you must also consult your doctor for advise regarding this. Discuss about Irritable Bowel Syndrome with him and the steps you need to take. You also need to consult your doctor to rule out two other conditions which are similar, but which do not seem likely in your case, ulcerative colitis and Crohns disease. You can look up these sites for more info: http://www.mayoclinic.com/health/irritable-bowel-syndrome/DS00106 http://digestive.niddk.nih.gov/ddiseases/pubs/ibs/
Excessive flatulence is a common enough problem. This is usually related to diet. Sometimes excessive flatulence can be related to medical problems like gall bladder stones, IBS, Appendicitis, etc. So a medical consultation to rule these out would be necessary as a first step. Besides this, you have to modify your diet to reduce gas producing foods. You can look up here for more info on this and foods to avoid: http://www.betterhealth.vic.gov.au/BHCV2/bhcarticles.nsf/pages/Flatulence?OpenDocument http://www.heptune.com/farts.html
I hope this answer was helpful. If you need more information, feel free to ask. For accepting this answer, please click on the green 'accept' button below. Feedback/Bonus will be warmly appreciated.