Can I write off miles for traveling between my hotel and the grocery store? I know normally you can't write off miles when commuting, but what if I am living out of town for my business?
First of all, it's not clear what you mean by "my business." If you are an employee (you get a W-2) you cannot deduct any business expenses (at least for years 2018 through 2025).
The second question is what you mean by "living out of town." If you are working out of town for a long-term or indefinite period, you cannot deduct your travel expenses. And why do you call the out-of-town travel "commuting"? Here is an excerpt from IRS Publication 463.
"Generally, a temporary assignment in a single location is one that is realistically expected to last (and does in fact last) for 1 year or less. However, if your assignment or job is indefinite, the location of the assignment or job becomes your new tax home and you can't deduct your travel expenses while there. An assignment or job in a single location is considered indefinite if it is realistically expected to last for more than 1 year, whether or not it actually lasts for more than 1 year."
If you are self-employed and your out-of-town assignment is temporary, as defined above, you could deduct local transportation for business purposes as a business expense. But what is the business purpose of going to the grocery store? Do you work at the grocery store? If you're just going to the store to pick up food for yourself, that's not business mileage.
The short answer is no.
The IRS has two sets of rules, for travel and transportation. Travel is traveling away from your tax home to work in another location that is distant enough that an overnight stay or longer is required. Transportation is getting around from place to place in your tax home or wherever else you are working.
If you are self-employed, you may deduct travel and lodging expenses when you are working away from your "tax home" far enough that overnight travel is required, as long as the work way from your tax home is temporary (meaning expected to last and actually lasts less than 1 year). If your assignment is expected to last more than one year, or if there is no particular exception of an end date, then it is not temporary and nothing is deductible.
Once you have traveled to your temporary work location, the transportation rules take over. You can't deduct your daily commute (to and from your hotel or other lodging) and you can't deduct personal miles (food, entertainment, etc.) any more than you could when living and working at your tax home.
See IRS publication 463 chapters 1 and 4.