Essentially, if you know the energy and divide it by the volume, you get energy density. And to get energy (in Joules), it is jut the power (in Watts) multiply by the duration (in secs).
And for free space vs medium with refractive index, the energy dissipation comes in the form of Lambert...