Microscopic Definition of Heat and Work If I am given a statistical system, then I can define state-variables like Energy, Entropy or  other observables, and then I can (at least for equilibrium states) give the infinitesimal change of energy as:
$$ d E = T dS + K  dx $$
Here x means any observable and K means the depending force, for example if x is the volume $V$, then K is minus the pressure $-p$. What I read all the time is
$$ d E = \delta Q + \delta W $$
Is there a general microscopic way to define what part of the above formula is $\delta W$ and what part is $\delta Q$ ?
For example, for reversible processes, $\delta Q = T dS$ and $\delta W = Kdx$. But what if I'm looking at an arbitrary process?
 A: There are different answers to your question. I will put here what I believe is the more popular in the literature.
We start from the quantum mechanical expression for the energy average
$$ \langle E\rangle = \mathrm{Tr}\{\hat{H}\hat{\rho}\}$$
where $\mathrm{Tr}$ denotes the trace (a quantum 'integration' over the degrees of freedom), $\hat{H}$ is the Hamiltonian operator associated to the system and $\hat{\rho}$ is the density operator that describes the quantum state of the system. Differentiating both sides
$$ \langle dE\rangle = \mathrm{Tr}\{(d\hat{H})\hat{\rho}\} + \mathrm{Tr}\{\hat{H}(d\hat{\rho})\} ,$$
where the first term is what we call work and the second what we call heat,
$$ \langle dE\rangle = \langle \delta W\rangle + \langle \delta Q\rangle .$$
Those can be put in a more familiar form. For instance if the Hamiltonian depends on variable $x$ then
$$ \langle \delta W\rangle = \mathrm{Tr}\{(d\hat{H})\hat{\rho}\} = \mathrm{Tr}\left\{\left(\frac{\partial \hat{H}}{\partial x} dx\right)\hat{\rho}\right\} = \left\langle\frac{\partial \hat{H}}{\partial x} dx\right\rangle$$
A: Let's consider an exchange dE of energy. Using the statistical definition of $E=\sum p_i\epsilon _i$ as the average value of the energies of the microscopic states : 
\begin{equation}\label{eq:dE}
    dE = \sum\epsilon_i dp_i  + \sum p_i d\epsilon_i
\end{equation}
We can see that the change in average energy is partly due to a change in the distribution of probability of occurrence of microscopic state $\epsilon_i$ and partly due to a change in the eigen values $\epsilon_i$ of the N-particles microscopic eigen states. 
Now taking the statistical definition of entropy as the average lack of information $S=-k_B\sum p_i ln(p_i)$. Using $\beta = 1/k_B T$ and noting that $\sum dp_i=d\sum p_i = 0$, one can write:
\begin{equation}
\begin{array}{ccccc}
TdS &=& -1/\beta (\sum dp_i ln(p_i) &+& \sum p_i\frac{dp_i}{p_i})\\
    &=& -1/\beta (\sum dp_i ln(\frac{e^{-\beta\epsilon_i}}{Z})  &+& d\sum p_i)\\
    &=& -1/\beta (\sum  -\beta\epsilon_i dp_i - lnZ\sum  dp_i )& &\\
    &=& \sum \epsilon_i  dp_i
\end{array}
\end{equation}
So here we can identify the change in entropy at constant temperature (change in the distribution probability over the microscopic states) as the first term in equation for dE. We have decided to call this term heat and note it $\delta Q$ .
