I am booked with British airways for Tampa-Chennai, India. The flight transits in Chicago and London. Do I have to go through any immigration and custom formalities in Chicago again?
The Tampa - Chicago flight is an arriving domestic flight in Chicago, so obviously there are no formalities. The Chicago - Chennai flight is a departing international flight in Chicago, which you also don't go through immigration formalities for, because the US doesn't have any exit immigration formalities.
In fact, many times departing international flights in US airports will share the same gates as departing domestic flights (which I have specifically experienced in the Chicago O'Hare airport), and you would not know the difference except by looking at the destination signs. Boarding a departing international flight is the same procedurally as boarding a departing domestic flight. So a domestic-to-international transfer is no different procedurally from a domestic-to-domestic transfer.
There are no customs nor immigration controls between Chicago and Tampa—they are both in the United States. (I assume you mean Tampa, Florida.)
Assuming you are on one ticket, AA to BA: There is an airside bus from Chicago Terminal 3G and 3K to Terminal 5M, so no security either. There are stops near to Gate K19 and Gate G17 [as I remember]. Under one ticket, your baggage will be through-checked to Chennai.
At BA Terminal 5 there is a security check, but no immigration or customs. No terminal change at LHR.