Yes you can sleep in your car in Yellowstone national park.
It's best to get a designated campsite to camp in your car in Yellowstone so you won't have any issues.
I've heard of a few people sleeping in their car just anywhere in Yellowstone and they got woken up by a park ranger and told they could not sleep there.
Not sure if things have changed but if you do sleep anywhere in Yellowstone national park in your car or RV the worse that would happen is you get a knock at night and then told you have to move to a designated campsite.
There are several designated campsites with electricity, water etc that you can get pretty cheap.
I find it's worth it to pay for a campsite and have the electricity, water etc available even when sleeping in my car.