Yes, it may be possible to buy, register and insure a car in one state while holding a driver's license in a different state. There would need to be a good reason to be doing so such as you are going to school / college in one state where you want to buy, register and insure a car but want to keep your license from your home state which you plan to return.
Another couple of circumstances that may be plausible reasons for you to buy and insure a car in one state and have a driver's license for another state are if you are in the military and stationed outside of your home state or perhaps having a car garaged at your vacation home in a different state.
If want to buy, register and insure a car in one state and then transport it back to garage and drive it in your home state where your driver's license was issued then this normally would not work. State laws usually require you to register and plate your vehicle in the state where the car will be primary driven and especially if you are a resident of that state.
Insurance companies are similar since they also normally require you to insure your vehicle in the state which the car will be driven and garaged for the majority of the year. This means typically one should buy insurance in the state that your car is registered since that is where in a normal situation where your car will be located, driven and garaged.