401k vs stock investments when it comes to taxes

I'm a bit confused about what makes more economical sense when it comes to investing and taxes: 401k investments vs investments on your own. I'll try to formulate my questions as a simple example.

Let's consider these two options:

1. You invest in a 401k (bonds and index funds such as S&P 500) and when you retire after 40 years you have \$1mil in it. 2. You invest yourself in a low cost ETF (say S&P 500) and bonds at the same ratio as option 1 and you also have \$1mil after 40 years.

Now, when it comes to making withdrawals (after 60 yo), it seems to me that you'll be taxed less for option 2. If you're withdrawing \$200k from the 401k and that's all the income you have, you'll be taxed at a regular income tax rate (currently about 21% effective rate for the \$200k). But if you withdraw \$200k from the investments, that's taxed as capital gain and since you have no other income you'd be taxed 0%. A big assumption here is that the capital gains tax will stay at 0% if you have no other income in 40 years time. I understand that your contributions for option 1 to the 401k are pre-tax, and the funds used to make investments on your own for option 2 are post-tax. So you were taxed for the \$200k you put in the investment to begin with in 2. But you're only taxed on the contributions you made, and not on the profits for 2. Whereas with option 1, you're taxed for everything you withdraw, including profits from the 401k investments at a higher rate. Over the \\$1mil withdrawal, that difference is significant.

Am I missing anything here?

Thanks!

UPDATE: I figured out at least one thing I am missing. In option 2, the dividends that are paid to you are taxed (unless they're paid in the form of more stock, which for an S&P 500 ETF is not possible). Even if you re-invest the dividends, you still have to pay taxes on them. This will lower your profits in option 2.