In my book, it says 'in the plural, all time words normally take B+acc'. But in a text appears ''за последние 20 лет''. Can I say also 'B последние 20 лет'? If both за and B can be used, is there any difference in meaning? Thanks in advance.
Basically you can.
However, note that the choice actually depends on how these time intervals are related to the verb.
"В" + acc.pl. is more used with imperfective verbs, "за" + acc.pl. with perfective ones.
Note that "за" is practically impossible with a continuous activity; it presupposes either series of events/processes (homogeneous or not), or some event resulting from a background activity which had been happening through the period (e.g. "за эти три года я понял главное: ..."); in the latter case, "в" + acc. is, in turn, normally impossible.