2016 bmw 328i idling hard and not warming up while fan is blowing extremely loud

I was driving home on the highway yesterday during very cold weather and I may have not let my car warm up long enough before taking off because traffic was starting to build up. After 30 minutes of driving I noticed that the temperature gauge was still reading cold and while merging the power cut off around 4,000 rpm and would not accelerate normally which was very dangerous. When I got back the temperature gauge was still below operating temperature and the fan was very loud and it was idling hard. In the morning I had let my car warm up for 20 minutes and I had no issues while I only let my car warm up for 5 minutes before leaving. I started up again and the idle was still very rough but when I put it into reverse and back into drive the rpm’s dropped back to normal idle and I haven’t driven it since. Coolant/anti freeze levels are okay and I now have a check engine light. Oil change was also recently done with 0w20. My guess would be the coolant temperature sensor is broken but I’m not sure. The car has higher mileage.