Consider the following regression specification where, $t$ is time, $c$ is the firm, $y$ is an outcome and $x$ is a variable of interest.
$$
y_{c,t} = \alpha + \beta x_{c,t} + \varepsilon_{c,t}
$$
There are three types of omitted variables:
- Variables that vary with time but are the same across firms. Examples might be weather conditions, inflation rate, intrest rates, wages, demand shocks (if firms operate on the same market) Let's call these $\gamma_t$ with only a subscript $t$ to indicate that they only vary over time.
- Variables that vary over firms but are constant across time. Examples can be firm location, or brand image, productivity (if this remains constant over time), etc. Let's call these $\delta_c$
- Variables that vary both over firms and over time. Examples might be firm output or profits. Let's call these $\chi_{c,t}$.
As all these variables are omitted, they enter the error term $\varepsilon_{c,t}$, so:
$$
\varepsilon_{c,t} = \delta_c + \gamma_t + \chi_{c,t}
$$
This decomposition can always be made by setting $\delta_c$ to be the expectation of $\varepsilon_{c,t}$ conditional on $c$ and $\gamma_t$ to be the expectation of $\varepsilon_{c,t}$ conditional on $t$. In particular, letting $\varepsilon_{.t}$ be the conditional mean of $\varepsilon$ on $t$, and $\varepsilon_{c.}$ the conditional mean conditional on $c$. We have:
$$
\varepsilon_{c,t} = \underset{\delta_c}{\underbrace{\varepsilon_{c.}}} + \underset{\gamma_t}{\underbrace{\varepsilon_{.t}}} + \underset{\chi_{c,t}}{\underbrace{(\varepsilon_{c,t} - \varepsilon_{c.} - \varepsilon_{.t})}}.
$$
In order to be able to get a good estimate of $\beta$ in the original regression you have to assume that $\varepsilon$ and $x$ are orthogonal:
$$
\mathbb{E}(\varepsilon x) = 0.
$$
Using the decomposition above, this gives the requirement that:
$$
\mathbb{E}(\delta x) + \mathbb{E}(\gamma x) + \mathbb{E}(\chi x) = 0
$$
Now, you might be worried that this does not hold.
Fixed effects provides a manner to solve this as long as the orthogonality condition still holds for the 3rd type of omitted variables, i.e. as long as:
$$
\mathbb{E}(\chi x) = 0
$$
Indeed, writing out the error term $\varepsilon_{c,t}$ in the regression we get:
$$
y_{c,t} = \alpha + \delta_c + \gamma_t + \beta x_{c,t} + \chi_{c,t}.
$$
The $\delta_c$ and $\gamma_t$ terms are captured by the firm and time fixed effects dummies, so we can identify as long as $x$ is orthogonal to $\chi$.
Another way to see that $\beta$ is identified is to first take the mean of the regression over all firms, time periods and time and firms. This gives:
$$
\begin{align*}
&y_{.t} = \alpha + \gamma_t + \beta x_{.,t},\\
&y_{c.} = \alpha + \delta_c + \beta x_{c.},\\
&y_{..} = \alpha + \beta x_{..}
\end{align*}
$$
(Notice that $\chi_{c.} = \chi_{.t} = \chi_{..} = \delta_. = \gamma_. = 0$ as, $\chi_{c,t} = \varepsilon_{c,t} - \varepsilon_{.t} - \varepsilon_{c.}$)
Adding the last and subtracting the first two of the original regression gives:
$$
(y_{c,t} + y_{..} - y_{c.}- y_{.t}) = \beta(x_{c,t} + x_{..} - x_{c.} - x_{.t}) + \chi_{c,t}
$$
So $\beta$ is identified by regressing $y_{c,t} + y_{..} - y_{c,.} - y_{.t}$ on $x_{c,t} + x_{..} - x_{c.} - x_{.t}$ .
And when two-way fixed effects control for both time-variant and time-invariant variables, why researchers also include some independent variables? In short, is this redundant to add the other control variables when time-variant and time-invariant variables have been controlled by time and year fixed effects?
Now it is important to add to the regression all other independent variables that fit into the 3rd category above, especially if you think they do not satisfy the orthogonality condition. For example, if you think $y$ is directly influenced by, say, firm profits (which is time and firm varying, so captured by $\chi$) and that $x$ is also correlated with firm profits, you will not be able to identify $\beta$ if you do not observe and control for firm profits.