1999 BMW 323 I engine light ON

My mecanic checked with a scanner the cause of the engine light on and found out codes 1186 and 1187 which mean according to him sensors needed to be replaced. He did replaced both of them, then I drove the car for about 50 miles the engine light come back again.

Any idea, please advise

A look shows those codes pertain to the heater circuit on the O2 sensors, which I assume is what he replaced. Those codes do NOT mean the O2 sensor heater circuits are bad; only that a problem exists in that particular circuit, which can include wiring, connectors, fuses, etc.

Maybe the problem is nothing more than a blown fuse or corroded wire connector on the sensor harness.
About all I can suggest is that the codes be pulled again and verify that the current Check Engine Light is not due to something else.

You might consider dropping by a local AutoZone, Checkers, etc. and have them pull the codes for you. They will do this for you free. If the '86 and '87 are back then you should return to the mechanic and have the heater circuit checked. It’s easy to do.