Is the measurement of distance and position of remote celestial bodies accurate? Considering that light is affected by gravity, how accurate are measurements of distant stars and galaxies?
When light passes through objects with great mass, such as Jupiter size planets, stars, or black holes, shouldn't it change its course and result in a deviation of trajectory? Does the light we see with telescopes when observing the many celestial bodies in the sky pinpoint the real location of such bodies in the past, or was its past location divergent from the point in space indicated by the light reaching us today?
Large masses can bend light, but space is largely empty.  The light from distant stars and galaxies rarely passes close enough to another star or galaxy to have deviated. On the few occasions when it does, it is special and notable.
For example, the Einstein cross looks like four quasars in a (very small) square, with a galaxy in front of it.  In fact it is four images of one quasar, the light having been bent by the gravity of the foreground galaxy.  In this case the image of the quasar is split up and moved by a few thousanths of a degree, because there is a very exact alignment of a quasar and a galaxy.
Such examples are rare.  For nearly everything else the light has travelled in a straight line through flat and empty space. The light we see pinpoints the location that the object was when the light was emitted.
An exception to this is that our own sun (and to a lesser extent the other planets) create local distortions. In very high accuracy measurements this can be taken into account. But the distortions are very small and as we know the location of the sun, they can be fully taken into account.
Although the light travels in straight lines, it can be very hard to measure the distance to stars and galaxies.  Often there is considerable uncertainty on the distance of astronomical objects. But this is not a result of gravity, it is just because measuring distance is hard.