With tikzmark you can declare stuff nodes, with tikz you can daw boxes around nodes, and eso-pic allows you to shuffle it on the background.
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{tikzmark,fit}
\usepackage{eso-pic}
\begin{document}
\[A = \det\left(\begin{array}{cccc} a_{11} & \tikzmarknode{a12}{a_{12}} & \ldots & a_{1n} \\
\tikzmarknode{a21}{a_{21}} & a_{22} & \ldots & \tikzmarknode{a2n}{a_{2n}} \\
\ldots & \ldots & \ldots & \ldots \\
a_{n1} & \tikzmarknode{an2}{a_{n2}} & \ldots & a_{nn} \\
\end{array}\right)\]
\AddToShipoutPictureBG*{\begin{tikzpicture}[overlay,remember picture]
\node[fit=(a12) (an2),draw=red,fill=red,fill opacity=0.2]{};
\node[fit=(a21) (a2n),draw=blue,fill=blue,fill opacity=0.2]{};
\end{tikzpicture}}
\end{document}

Or
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{tikzmark,fit}
\usepackage{eso-pic}
\begin{document}
\[A = \det\begin{pmatrix} a_{11} & \cdots & \tikzmarknode{a1i}{a_{1i}} & \cdots & a_{1n} \\
\vdots & \ddots & \vdots & \reflectbox{$\ddots$} & \vdots \\
\tikzmarknode{aj1}{a_{j1}} & \cdots & a_{ji} & \cdots & \tikzmarknode{ajn}{a_{jn}} \\
\vdots & \reflectbox{$\ddots$} & \ldots & \ddots & \vdots \\
a_{n1} & \cdots &\tikzmarknode{ani}{a_{ni}} & \cdots & a_{nn} \\
\end{pmatrix}
\]
\AddToShipoutPictureBG*{\begin{tikzpicture}[overlay,remember picture]
\node[fit=(a1i) (ani),draw=red,fill=red,fill opacity=0.2]{};
\node[fit=(aj1) (ajn),draw=blue,fill=blue,fill opacity=0.2]{};
\end{tikzpicture}}
\end{document}

If you cannot install the recent version of tikzmark, you can do
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{fit}
% overleaf
\newcommand{\tikzmarknode}[3][]{\ifmmode%
\tikz[remember picture,baseline=(#2.base)]{\node[inner sep=0pt,#1](#2){$#3$};}%
\else%
\tikz[remember picture,baseline=(#2.base)]{\node[inner sep=0pt,#1](#2){#3};}%
\fi}
\usepackage{eso-pic}
\begin{document}
\[A = \det\begin{pmatrix} a_{11} & \cdots & \tikzmarknode{a1i}{a_{1i}} & \cdots & a_{1n} \\
\vdots & \ddots & \vdots & \reflectbox{$\ddots$} & \vdots \\
\tikzmarknode{aj1}{a_{j1}} & \cdots & a_{ji} & \cdots & \tikzmarknode{ajn}{a_{jn}} \\
\vdots & \reflectbox{$\ddots$} & \ldots & \ddots & \vdots \\
a_{n1} & \cdots &\tikzmarknode{ani}{a_{ni}} & \cdots & a_{nn} \\
\end{pmatrix}
\]
\AddToShipoutPictureBG*{\begin{tikzpicture}[overlay,remember picture]
\node[fit=(a1i) (ani),draw=red,fill=red,fill opacity=0.2]{};
\node[fit=(aj1) (ajn),draw=blue,fill=blue,fill opacity=0.2]{};
\end{tikzpicture}}
\end{document}
! Undefined control sequence. l.13 ...\begin{array}{cccc} a_{11} & \tikzmarknode {a12}{a_{12}} & \ldots & a...– Giuliano Malatesta Apr 11 '19 at 10:27\tikzmarknodehas been added to thetikzmarklibrary last year. – Apr 11 '19 at 10:29tikzmarklibrary and use\newcommand{\tikzmarknode}[3][]{\ifmmode% \tikz[remember picture,baseline=(#2.base)]{\node[inner sep=0pt,#1](#2){$#3$};}% \else% \tikz[remember picture,baseline=(#2.base)]{\node[inner sep=0pt,#1](#2){#3};}% \fi}instead. (I added an example as well.) – Apr 11 '19 at 10:34