How does a bi-directional electricity meter know import from export?
Voltage and current waveforms have an amplitude but they also have a phase relationship: -



The left picture shows voltage and current waveforms in phase i.e. they rise and fall together. The right hand picture illustrates a phase lag on the current.

The red curves for both is power and even though the amplitudes of voltage and current are the same in both pictures, the average power in the right hand picture (what you are billed on) is lower.

Here are more extreme examples: -



The left picture shows current lagging voltage by 90 degrees and the average power is zero (there are equal amounts of power taken from the supply as given back to the supply). The right picture shows a negative average power because the current's phase angle has moved to a point where it is generally inverted i.e. it's positive peaks are closer to the inverted voltage waveform's negative peaks. This is an example where power is flowing out from a "user" and back into the power grid.


  How does the meter differentiate between imported and exported energy?


Imported energy is when the current is flowing into the load as typified by the top two diagrams. Average power is positive. Exported power would be a negative value of average power as typified by the lower right hand diagram.

For sine waves, reactive power is the average of VI sin(\$\phi\$). True power is the average of VI cos(\$\phi\$). So, as soon as the phase angle (\$\phi\$) is not zero you get some reactive power and this peaks when \$\phi\$ = 90 degrees.

Pictures taken from here and here.

The above explanation is for a single phase but the same applies to 3 phase systems.