I am having difficulty understanding the semantics of the "=" sign in various contexts. It seems that in most cases it denotes an identity relation. But in some cases I get a (possibly wrong) feeling that we are talking about the variable symbols themselves and assigning values to them. In a book on logic i am reading, ":=" is used for this.
Let's take a concrete example: the wikipedia article on Fermat's Last Theorem.
How should I understand the expression here: "The cases n = 1 and n = 2 have been known since antiquity to have infinitely many solutions."?
I think what the author is saying here is that the formula "an + bn = cn " is true for an infinite set of positive integer variable assignments a, b, c if the value of variable n is 1 or 2.
Another example from the article Fundamental Concepts in Programming Languages:
It seems to me that the author is assigning values to terms a and b.
Also, in some books on calculus, authors define a function with an expression such as "f(x) = x2" and then can consider its value at some point with an expression similar to this: "for x = a, the value of the function is a2 ".
I don't understand why some people use the "=" sign from the object language for statements about language.

In computer science, yes, the equal sign very often means assignment. In mathematics it never does. I mean, you could perhaps find a quirky math book, but that would be very non-standard mathematical expression.
In your logic textbook the author acknowledges that his talk of "assignment" and use of := is all metaphorical to a computer. But the mathematically technical sense of what $P:=T$ means, is that the formula $(P\land Q)$ is what is called a truth-function. It is actually a function $f(x,y)$ which accepts truth-value arguments and returns a truth-value. In particular $f(T,T)=T$, and we could metaphorically describe what's going on here as $P:=T$ and $Q:=T$. But really, from the mathematical perspective, it's just the evaluation of a function -- there is no register at which data is stored.
And when you consider a variable $n$ and say something like "let $n=1$" we are not assigning 1 to $n$ in any literal sense. A metaphor might make this seem familiar, and insofar as that goes, it's a fine metaphor. But all we're really saying is that "$a^n+b^n=c^n$" is a sentence (or family of sentences, if you like) indexed by $n$. So you could regard "$n=1$" as mere reference to the sentence $a+b=c$.
Similarly if you consider the statement $1+2+\cdots+n = \frac{n(n+1)}{2}$, this is a sentence indexed by $n$ also. If we talk about the case where $n=1$ we are merely making reference to the sentence "$1=\frac{1(1+1)}{2}$".
I will admit that there are subtle ways in which mathematicians use the equality symbol to mean different things. Like you said, it can sometimes be an opaque way to talk about the evaluation of a function and it can even be, in the case of $f(x)=x^2$, a way of defining what $f$ is. Equality can be used for the assertion that some two things, previously defined, are in fact equal -- but it can also be a way of defining some objects. All of these are subtly different meanings, and mathematicians (myself included) are often barely aware of the different ways that they use equality in their day jobs.
But we keep living with this ambiguity because it hasn't caused serious problems, and we already have enough weird symbols.