How do we know what we observe is x light-years away? When we say the sun we see ‘now’ is from 8 minutes ago, I understand that - since we already know the distance to the sun. How do we measure distances to other objects?
Great question! Measuring distances is a very important problem in Astronomy and it is very hard to do.
So first of all you are absolutely right distances and light-years are directly related, light-years are simply a convenient way to state a distance.
Let me give you three typical ways of how Astronomers can determine distances to other objects:
One way is to use our movement around the sun to see distant stars from a slightly different angle throughout the year. This leads to a small parallax of nearby stars which we can use to calculate the distance using some triangle geometry. See for example http://star-www.st-and.ac.uk/~fv/webnotes/chapt14.htm
Another way we measure distance directly is by knowing how bright something is intrinsically. Then we look at how bright it appears in the sky and the dimmer it is the further we are away from it. Just like a lamp appears darker the further you are away from it since the light spreads out more. We for example have a good understanding of the absolute brightness of some supernovae and some stars that oscillate in brightness (cepheid stars).
The first one works well for our neighboring stars. The second one also works for other somewhat nearby galaxies. To make this more accurate we usually use a distance ladder, where one type of measurement helps us make sure the next one that goes even further out is still accurate.
For super far away galaxies, i.e. their light was sent so long ago that a good fraction of the universe's history has passed since, we have another way. See as the universe expands, the light gets stretched: blue light becomes redder, red light becomes infrared, and so on. Since from decades of very detailed surveys of the sky, we have a pretty accurate model of the history of the universe we can relate how much the light has shifted to a distance in light-years. Here as an example is GN-z11 one of the most distant objects we know: https://en.wikipedia.org/wiki/GN-z11
Image of GN-z11: (credit: Hubble Space Telescope, NASA, ESA)
Artist conception of how GN-z11 looked like when the light was emitted: (credit: Pablo Carlos Budassi)
We know this galaxy has to be rather blue, but it appears completely red when we observed it. This lets us calculate that its light has been traveling to us for 13.4 billion years (almost the entire age of the universe which is around 13.7 billion years). Since then the space in between has expanded so much that today this galaxy is around 32 billion light-years away from us.
Also as a reminder all of these methods have significant uncertainty associated, we can't do these measurements down to a meter. Usually, these methods are only accurate to a few percent.